2fas-server/tests/mobile/mobile_device_test.go

52 lines
1.2 KiB
Go
Raw Normal View History

2023-03-12 14:59:53 +01:00
package tests
import (
"fmt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/twofas/2fas-server/tests"
"net/http"
"testing"
)
func TestMobileDeviceTestSuite(t *testing.T) {
suite.Run(t, new(MobileDeviceTestSuite))
}
type MobileDeviceTestSuite struct {
suite.Suite
}
func (s *MobileDeviceTestSuite) SetupTest() {
tests.DoSuccessDelete(s.T(), "mobile/devices")
}
func (s *MobileDeviceTestSuite) TestCreateMobileDevice() {
type testCase struct {
deviceName string
expectedHttpCode int
}
testsCases := []testCase{
{deviceName: "", expectedHttpCode: 400},
{deviceName: " ", expectedHttpCode: 400},
{deviceName: " ", expectedHttpCode: 400},
{deviceName: "john`s android", expectedHttpCode: 200},
{deviceName: "john ", expectedHttpCode: 200},
{deviceName: " john doe", expectedHttpCode: 200},
}
for _, tc := range testsCases {
response := createDevice(tc.deviceName)
assert.Equal(s.T(), tc.expectedHttpCode, response.StatusCode)
}
}
func createDevice(name string) *http.Response {
fcmToken := "some-fake-token"
payload := []byte(fmt.Sprintf(`{"name":"%s","platform":"android","fcm_token":"%s"}`, name, fcmToken))
return tests.DoPost("mobile/devices", payload, nil)
}