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
129 lines
3.6 KiB
Go
129 lines
3.6 KiB
Go
package tests
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/suite"
|
|
"github.com/twofas/2fas-server/tests"
|
|
)
|
|
|
|
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() {
|
|
tests.RemoveAllMobileIconsCollections(s.T())
|
|
}
|
|
|
|
func (s *IconsCollectionsTestSuite) TestCreateIconsCollection() {
|
|
payload := []byte(`
|
|
{
|
|
"name":"facebook",
|
|
"description":"desc",
|
|
"icons":["123e4567-e89b-12d3-a456-426614174000"]
|
|
}
|
|
`)
|
|
|
|
var IconsCollection *iconsCollectionResponse
|
|
tests.DoAdminAPISuccessPost(s.T(), "mobile/icons/collections", payload, &IconsCollection)
|
|
|
|
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
|
|
tests.DoAdminAPISuccessPost(s.T(), "mobile/icons/collections", payload, &iconsCollection)
|
|
|
|
updatePayload := []byte(`
|
|
{
|
|
"name":"meta",
|
|
"icons":["icon-1", "icon-2"]
|
|
}
|
|
`)
|
|
|
|
var updatedIconsCollection *iconsCollectionResponse
|
|
tests.DoAdminSuccessPut(s.T(), "mobile/icons/collections/"+iconsCollection.Id, updatePayload, &updatedIconsCollection)
|
|
|
|
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
|
|
tests.DoAdminAPISuccessPost(s.T(), "mobile/icons/collections", payload, &iconsCollection)
|
|
|
|
tests.DoAdminSuccessDelete(s.T(), "mobile/icons/collections/"+iconsCollection.Id)
|
|
|
|
response := tests.DoAPIGet(s.T(), "mobile/icons/collections/"+iconsCollection.Id, nil)
|
|
assert.Equal(s.T(), 404, response.StatusCode)
|
|
}
|
|
|
|
func (s *IconsCollectionsTestSuite) TestFindAllIconsCollections() {
|
|
payload := []byte(`
|
|
{
|
|
"name":"facebook",
|
|
"icons":["icon-1", "icon-2"]
|
|
}
|
|
`)
|
|
tests.DoAdminAPISuccessPost(s.T(), "mobile/icons/collections", payload, nil)
|
|
|
|
payload2 := []byte(`
|
|
{
|
|
"name":"google",
|
|
"description":"google google",
|
|
"icons":["123e4567-e89b-12d3-a456-426614174000"]
|
|
}
|
|
`)
|
|
tests.DoAdminAPISuccessPost(s.T(), "mobile/icons/collections", payload2, nil)
|
|
|
|
var IconsCollections []*iconsCollectionResponse
|
|
tests.DoAPISuccessGet(s.T(), "mobile/icons/collections", &IconsCollections)
|
|
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
|
|
tests.DoAdminAPISuccessPost(s.T(), "mobile/icons/collections", payload, &createdIconsCollection)
|
|
|
|
var IconsCollection *iconsCollectionResponse
|
|
tests.DoAPISuccessGet(s.T(), "mobile/icons/collections/"+createdIconsCollection.Id, &IconsCollection)
|
|
|
|
assert.Equal(s.T(), "just-one", IconsCollection.Name)
|
|
}
|