()
| 526 | } |
| 527 | |
| 528 | func (s *MessageSuite) Test_CreateMessage_onFormData() { |
| 529 | auth.RegisterAuthentication(s.ctx, nil, 4, "app-token") |
| 530 | s.db.User(4).AppWithToken(99, "app-token") |
| 531 | |
| 532 | t, _ := time.Parse("2006/01/02", "2017/01/02") |
| 533 | timeNow = func() time.Time { return t } |
| 534 | defer func() { timeNow = time.Now }() |
| 535 | |
| 536 | s.ctx.Request = httptest.NewRequest("POST", "/message", strings.NewReader(`title=mytitle&message=mymessage&priority=1`)) |
| 537 | s.ctx.Request.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| 538 | |
| 539 | s.a.CreateMessage(s.ctx) |
| 540 | |
| 541 | expected := &model.MessageExternal{ID: 1, ApplicationID: 99, Title: "mytitle", Message: "mymessage", Priority: intPtr(1), Date: t} |
| 542 | msgs, err := s.db.GetMessagesByApplication(99) |
| 543 | assert.NoError(s.T(), err) |
| 544 | assert.Len(s.T(), msgs, 1) |
| 545 | assert.Equal(s.T(), expected, toExternalMessage(msgs[0])) |
| 546 | assert.Equal(s.T(), 200, s.recorder.Code) |
| 547 | assert.Equal(s.T(), uint(1), s.notifiedMessage.ID) |
| 548 | } |
| 549 | |
| 550 | func (s *MessageSuite) withURL(scheme, host, path, query string) { |
| 551 | s.ctx.Request.URL = &url.URL{Path: path, RawQuery: query} |
nothing calls this directly
no test coverage detected