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

73 lines
1.6 KiB
Go
Raw Permalink Normal View History

2022-12-31 10:22:38 +01:00
package tests
import (
"fmt"
"math/rand"
"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
)
func TestWebServicesDumpTestSuite(t *testing.T) {
suite.Run(t, new(WebServicesDumpTestSuite))
}
type WebServicesDumpTestSuite struct {
suite.Suite
}
func (s *WebServicesDumpTestSuite) SetupTest() {
2024-03-16 15:41:30 +01:00
e2e_tests.RemoveAllMobileIcons(s.T())
e2e_tests.RemoveAllMobileIconsCollections(s.T())
e2e_tests.RemoveAllMobileWebServices(s.T())
2022-12-31 10:22:38 +01:00
}
func (s *WebServicesDumpTestSuite) TestWebServicesDump() {
createWebService(s.T())
createWebService(s.T())
2024-03-16 15:41:30 +01:00
response := e2e_tests.DoAPIGet(s.T(), "mobile/web_services/dump", nil)
2022-12-31 10:22:38 +01:00
assert.Equal(s.T(), 200, response.StatusCode)
}
func createWebService(t *testing.T) *webServiceResponse {
iconsCollection := createIconsCollection(t)
payload := []byte(`
{
"name":"` + fmt.Sprintf("service-%d", rand.Int()) + `",
"description":"another",
"issuers":["facebook", "m.facebook"],
"tags":["shitbook"],
"icons_collections":["` + iconsCollection.Id + `"]
}
`)
var webService *webServiceResponse
2024-03-16 15:41:30 +01:00
e2e_tests.DoAdminAPISuccessPost(t, "mobile/web_services", payload, &webService)
2022-12-31 10:22:38 +01:00
return webService
}
func createIconsCollection(t *testing.T) *iconsCollectionResponse {
icon := createIcon(t)
payload := []byte(`
{
"name":"just-one",
"description":"another",
"icons":["` + icon.Id + `"]
}
`)
var createdIconsCollection *iconsCollectionResponse
2024-03-16 15:41:30 +01:00
e2e_tests.DoAdminAPISuccessPost(t, "mobile/icons/collections", payload, &createdIconsCollection)
2022-12-31 10:22:38 +01:00
return createdIconsCollection
}