2fas-server/e2e-tests/icons/icons_collection_test.go

129 lines
3.6 KiB
Go
Raw Normal View History

2022-12-31 10:22:38 +01:00
package tests
import (
"testing"
2022-12-31 10:22:38 +01:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
2024-03-16 15:41:30 +01:00
"github.com/twofas/2fas-server/e2e-tests"
2022-12-31 10:22:38 +01:00
)
type iconsCollectionResponse struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Icons []string `json:"icons"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
func TestIconsCollectionsTestSuite(t *testing.T) {
suite.Run(t, new(IconsCollectionsTestSuite))
}
type IconsCollectionsTestSuite struct {
suite.Suite
}
func (s *IconsCollectionsTestSuite) SetupTest() {
2024-03-16 15:41:30 +01:00
e2e_tests.RemoveAllMobileIconsCollections(s.T())
2022-12-31 10:22:38 +01:00
}
func (s *IconsCollectionsTestSuite) TestCreateIconsCollection() {
payload := []byte(`
{
"name":"facebook",
"description":"desc",
"icons":["123e4567-e89b-12d3-a456-426614174000"]
}
`)
var IconsCollection *iconsCollectionResponse
2024-03-16 15:41:30 +01:00
e2e_tests.DoAdminAPISuccessPost(s.T(), "mobile/icons/collections", payload, &IconsCollection)
2022-12-31 10:22:38 +01:00
assert.Equal(s.T(), "facebook", IconsCollection.Name)
assert.Equal(s.T(), "desc", IconsCollection.Description)
assert.Equal(s.T(), []string{"123e4567-e89b-12d3-a456-426614174000"}, IconsCollection.Icons)
}
func (s *IconsCollectionsTestSuite) TestUpdateIconsCollection() {
payload := []byte(`
{
"name":"facebook",
"description":"another",
"icons":["123e4567-e89b-12d3-a456-426614174000"]
}
`)
var iconsCollection *iconsCollectionResponse
2024-03-16 15:41:30 +01:00
e2e_tests.DoAdminAPISuccessPost(s.T(), "mobile/icons/collections", payload, &iconsCollection)
2022-12-31 10:22:38 +01:00
updatePayload := []byte(`
{
"name":"meta",
"icons":["icon-1", "icon-2"]
}
`)
var updatedIconsCollection *iconsCollectionResponse
2024-03-16 15:41:30 +01:00
e2e_tests.DoAdminSuccessPut(s.T(), "mobile/icons/collections/"+iconsCollection.Id, updatePayload, &updatedIconsCollection)
2022-12-31 10:22:38 +01:00
assert.Equal(s.T(), "meta", updatedIconsCollection.Name)
assert.Equal(s.T(), []string{"icon-1", "icon-2"}, updatedIconsCollection.Icons)
}
func (s *IconsCollectionsTestSuite) TestDeleteIconsCollection() {
payload := []byte(`
{
"name":"facebook icons",
"icons":["icon-1", "icon-2"]
}
`)
var iconsCollection *iconsCollectionResponse
2024-03-16 15:41:30 +01:00
e2e_tests.DoAdminAPISuccessPost(s.T(), "mobile/icons/collections", payload, &iconsCollection)
2022-12-31 10:22:38 +01:00
2024-03-16 15:41:30 +01:00
e2e_tests.DoAdminSuccessDelete(s.T(), "mobile/icons/collections/"+iconsCollection.Id)
2022-12-31 10:22:38 +01:00
2024-03-16 15:41:30 +01:00
response := e2e_tests.DoAPIGet(s.T(), "mobile/icons/collections/"+iconsCollection.Id, nil)
2022-12-31 10:22:38 +01:00
assert.Equal(s.T(), 404, response.StatusCode)
}
func (s *IconsCollectionsTestSuite) TestFindAllIconsCollections() {
payload := []byte(`
{
"name":"facebook",
"icons":["icon-1", "icon-2"]
}
`)
2024-03-16 15:41:30 +01:00
e2e_tests.DoAdminAPISuccessPost(s.T(), "mobile/icons/collections", payload, nil)
2022-12-31 10:22:38 +01:00
payload2 := []byte(`
{
"name":"google",
"description":"google google",
"icons":["123e4567-e89b-12d3-a456-426614174000"]
}
`)
2024-03-16 15:41:30 +01:00
e2e_tests.DoAdminAPISuccessPost(s.T(), "mobile/icons/collections", payload2, nil)
2022-12-31 10:22:38 +01:00
var IconsCollections []*iconsCollectionResponse
2024-03-16 15:41:30 +01:00
e2e_tests.DoAPISuccessGet(s.T(), "mobile/icons/collections", &IconsCollections)
2022-12-31 10:22:38 +01:00
assert.Len(s.T(), IconsCollections, 2)
}
func (s *IconsCollectionsTestSuite) TestFindIconsCollection() {
payload := []byte(`
{
"name":"just-one",
"description":"another",
"icons":["123e4567-e89b-12d3-a456-426614174000"]
}
`)
var createdIconsCollection *iconsCollectionResponse
2024-03-16 15:41:30 +01:00
e2e_tests.DoAdminAPISuccessPost(s.T(), "mobile/icons/collections", payload, &createdIconsCollection)
2022-12-31 10:22:38 +01:00
var IconsCollection *iconsCollectionResponse
2024-03-16 15:41:30 +01:00
e2e_tests.DoAPISuccessGet(s.T(), "mobile/icons/collections/"+createdIconsCollection.Id, &IconsCollection)
2022-12-31 10:22:38 +01:00
assert.Equal(s.T(), "just-one", IconsCollection.Name)
}