mirror of
https://github.com/twofas/2fas-server.git
synced 2024-12-12 12:09:56 +01:00
794a93fa8a
* Fix e2e tests after separating admin api
108 lines
4.3 KiB
Go
108 lines
4.3 KiB
Go
package tests
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/suite"
|
|
query "github.com/twofas/2fas-server/internal/api/mobile/app/queries"
|
|
"github.com/twofas/2fas-server/tests"
|
|
)
|
|
|
|
func TestMobileNotificationsTestSuite(t *testing.T) {
|
|
suite.Run(t, new(MobileNotificationsTestSuite))
|
|
}
|
|
|
|
type MobileNotificationsTestSuite struct {
|
|
suite.Suite
|
|
}
|
|
|
|
func (s *MobileNotificationsTestSuite) SetupTest() {
|
|
tests.RemoveAllMobileNotifications(s.T())
|
|
}
|
|
|
|
func (s *MobileNotificationsTestSuite) TestCreateMobileNotification() {
|
|
payload := []byte(`{"icon":"features","platform":"android","link":"2fas.com","message":"demo","version":"0.1"}`)
|
|
|
|
var notification *query.MobileNotificationPresenter
|
|
|
|
tests.DoAdminAPISuccessPost(s.T(), "mobile/notifications", payload, ¬ification)
|
|
|
|
assert.Equal(s.T(), "android", notification.Platform)
|
|
assert.Equal(s.T(), "0.1", notification.Version)
|
|
assert.Equal(s.T(), "2fas.com", notification.Link)
|
|
assert.Equal(s.T(), "demo", notification.Message)
|
|
assert.Equal(s.T(), "features", notification.Icon)
|
|
}
|
|
|
|
func (s *MobileNotificationsTestSuite) TestUpdateMobileNotification() {
|
|
payload := []byte(`{"icon":"features","platform":"android","link":"2fas.com","message":"demo","version":"0.1"}`)
|
|
var notification *query.MobileNotificationPresenter
|
|
tests.DoAdminAPISuccessPost(s.T(), "mobile/notifications", payload, ¬ification)
|
|
|
|
payload = []byte(`{"icon":"youtube","platform":"ios","link":"new-2fas.com","message":"new-demo","version":"1.1"}`)
|
|
var updatedNotification *query.MobileNotificationPresenter
|
|
tests.DoAdminSuccessPut(s.T(), "mobile/notifications/"+notification.Id, payload, &updatedNotification)
|
|
|
|
assert.Equal(s.T(), "ios", updatedNotification.Platform)
|
|
assert.Equal(s.T(), "1.1", updatedNotification.Version)
|
|
assert.Equal(s.T(), "new-2fas.com", updatedNotification.Link)
|
|
assert.Equal(s.T(), "new-demo", updatedNotification.Message)
|
|
assert.Equal(s.T(), "youtube", updatedNotification.Icon)
|
|
}
|
|
|
|
func (s *MobileNotificationsTestSuite) TestDeleteMobileNotification() {
|
|
payload := []byte(`{"icon":"features","platform":"android","link":"2fas.com","message":"demo","version":"0.1"}`)
|
|
var notification *query.MobileNotificationPresenter
|
|
tests.DoAdminAPISuccessPost(s.T(), "mobile/notifications", payload, ¬ification)
|
|
|
|
tests.DoAdminSuccessDelete(s.T(), "mobile/notifications/"+notification.Id)
|
|
|
|
response := tests.DoAPIGet(s.T(), "mobile/notifications/"+notification.Id, nil)
|
|
assert.Equal(s.T(), 404, response.StatusCode)
|
|
}
|
|
|
|
func (s *MobileNotificationsTestSuite) TestDeleteNotExistingMobileNotification() {
|
|
id := uuid.New()
|
|
|
|
response := tests.DoAPIRequest(s.T(), "mobile/notifications/"+id.String(), http.MethodDelete, nil /*payload*/, nil /*resp*/)
|
|
|
|
assert.Equal(s.T(), 404, response.StatusCode)
|
|
}
|
|
|
|
func (s *MobileNotificationsTestSuite) TestFindAllNotifications() {
|
|
payload1 := []byte(`{"icon":"features","platform":"android","link":"2fas.com","message":"demo","version":"0.1"}`)
|
|
var notification1 *query.MobileNotificationPresenter
|
|
tests.DoAdminAPISuccessPost(s.T(), "mobile/notifications", payload1, ¬ification1)
|
|
|
|
payload2 := []byte(`{"icon":"youtube","platform":"android","link":"2fas.com","message":"demo2","version":"1.1"}`)
|
|
var notification2 *query.MobileNotificationPresenter
|
|
tests.DoAdminAPISuccessPost(s.T(), "mobile/notifications", payload2, ¬ification2)
|
|
|
|
var collection []*query.MobileNotificationPresenter
|
|
tests.DoAPISuccessGet(s.T(), "mobile/notifications", &collection)
|
|
|
|
assert.Len(s.T(), collection, 2)
|
|
}
|
|
|
|
func (s *MobileNotificationsTestSuite) TestDoNotFindNotifications() {
|
|
var collection []*query.MobileNotificationPresenter
|
|
|
|
tests.DoAPISuccessGet(s.T(), "mobile/notifications", &collection)
|
|
|
|
assert.Len(s.T(), collection, 0)
|
|
}
|
|
|
|
func (s *MobileNotificationsTestSuite) TestPublishNotification() {
|
|
payload := []byte(`{"icon":"features","platform":"android","link":"2fas.com","message":"demo","version":"0.1"}`)
|
|
var notification *query.MobileNotificationPresenter
|
|
tests.DoAdminAPISuccessPost(s.T(), "mobile/notifications", payload, ¬ification)
|
|
|
|
var publishedNotification *query.MobileNotificationPresenter
|
|
tests.DoAdminAPISuccessPost(s.T(), "mobile/notifications/"+notification.Id+"/commands/publish", payload, &publishedNotification)
|
|
|
|
assert.NotEmpty(s.T(), "published_at", notification.PublishedAt)
|
|
}
|