2022-12-31 10:22:38 +01:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-10-24 09:27:34 +02:00
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
|
2022-12-31 10:22:38 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/suite"
|
2023-01-30 19:59:42 +01:00
|
|
|
"github.com/twofas/2fas-server/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() {
|
2023-10-24 09:27:34 +02:00
|
|
|
tests.RemoveAllMobileIcons(s.T())
|
|
|
|
tests.RemoveAllMobileIconsCollections(s.T())
|
|
|
|
tests.RemoveAllMobileWebServices(s.T())
|
2022-12-31 10:22:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *WebServicesDumpTestSuite) TestWebServicesDump() {
|
|
|
|
createWebService(s.T())
|
|
|
|
createWebService(s.T())
|
|
|
|
|
2023-10-24 09:27:34 +02:00
|
|
|
response := 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
|
|
|
|
|
2023-10-24 09:27:34 +02:00
|
|
|
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
|
|
|
|
|
2023-10-24 09:27:34 +02:00
|
|
|
tests.DoAdminAPISuccessPost(t, "mobile/icons/collections", payload, &createdIconsCollection)
|
2022-12-31 10:22:38 +01:00
|
|
|
|
|
|
|
return createdIconsCollection
|
|
|
|
}
|