MCPcopy
hub / github.com/gotify/server / Test_CreateMessage_onFormData

Method Test_CreateMessage_onFormData

api/message_test.go:528–548  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

526}
527
528func (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
550func (s *MessageSuite) withURL(scheme, host, path, query string) {
551 s.ctx.Request.URL = &url.URL{Path: path, RawQuery: query}

Callers

nothing calls this directly

Calls 7

RegisterAuthenticationFunction · 0.92
intPtrFunction · 0.85
toExternalMessageFunction · 0.85
AppWithTokenMethod · 0.80
UserMethod · 0.80
CreateMessageMethod · 0.65

Tested by

no test coverage detected