test(project): 🧪 authentication v2

master
Xeronith 2022-11-14 12:15:13 +03:30
rodzic 376988eb57
commit 3b7a56002d
6 zmienionych plików z 160 dodań i 0 usunięć

Wyświetl plik

@ -45,6 +45,47 @@ func TestEchoApi(test *testing.T) {
}
}
func TestSignupApi(test *testing.T) {
input := &SignupRequest{
Username: "username",
Email: "email",
Password: "password",
}
if output, err := api.Signup(input); err != nil {
test.Fatal(err)
} else if output == nil {
test.Fail()
}
}
func TestVerifyApi(test *testing.T) {
input := &VerifyRequest{
Email: "email",
Token: "token",
Code: "code",
}
if output, err := api.Verify(input); err != nil {
test.Fatal(err)
} else if output == nil {
test.Fail()
}
}
func TestLoginApi(test *testing.T) {
input := &LoginRequest{
Email: "email",
Password: "password",
}
if output, err := api.Login(input); err != nil {
test.Fatal(err)
} else if output == nil {
test.Fail()
}
}
//region Initialization
func TestMain(main *testing.M) {

Wyświetl plik

@ -159,3 +159,36 @@ func TestSpiManager_Echo(test *testing.T) {
_ = result
}
func TestSpiManager_Signup(test *testing.T) {
manager := Conductor.SpiManager()
result, err := manager.Signup("username", "email", "password", nil)
if err != nil {
test.Fatal(err)
}
_ = result
}
func TestSpiManager_Verify(test *testing.T) {
manager := Conductor.SpiManager()
result, err := manager.Verify("email", "token", "code", nil)
if err != nil {
test.Fatal(err)
}
_ = result
}
func TestSpiManager_Login(test *testing.T) {
manager := Conductor.SpiManager()
result, err := manager.Login("email", "password", nil)
if err != nil {
test.Fatal(err)
}
_ = result
}

Wyświetl plik

@ -5,3 +5,7 @@ import "testing"
func Test_Local_Echo(t *testing.T) {
Run(t, apiLocal, echo)
}
func Test_Local_Signup(t *testing.T) {
Run(t, apiLocal, signup)
}

Wyświetl plik

@ -5,3 +5,7 @@ import "testing"
func Test_Remote_Echo(t *testing.T) {
Run(t, apiRemote, echo)
}
func Test_Remote_Signup(t *testing.T) {
Run(t, apiRemote, signup)
}

Wyświetl plik

@ -25,11 +25,16 @@ var (
)
func TestMain(main *testing.M) {
// logging
logger := logging.NewLogger(false)
logger.SetLevel(logging.LEVEL_SUPPRESS_SYS_COMP)
// configuration
configuration := settings.NewTestConfiguration()
configuration.GetMySQLConfiguration().SetDatabase("greatape")
// factories
operationsFactory := operations.NewFactory()
handlersFactory := handlers.NewFactory()
// providers
measurementsProvider := analytics.NewInfluxDbProvider(configuration, logger)
emailProvider := email.NewProvider(logger)
smsProvider := sms.NewProvider(logger)

Wyświetl plik

@ -0,0 +1,73 @@
package test
import (
"fmt"
"math/rand"
"time"
. "rail.town/infrastructure/components/api/protobuf"
. "rail.town/infrastructure/components/contracts"
)
func signup(api IApi) error {
rand.Seed(time.Now().UnixNano())
var (
token, code string
id = 100000 + rand.Intn(899999)
username = fmt.Sprintf("u%d", id)
email = fmt.Sprintf("%s@domain.com", username)
password = "AaBbCc1$"
)
// Signup
{
input := &SignupRequest{
Username: username,
Email: email,
Password: password,
}
output, err := api.Signup(input)
if err != nil {
return err
}
token = output.Token
code = output.Code
}
// Verify
{
input := &VerifyRequest{
Email: email,
Token: token,
Code: code,
}
output, err := api.Verify(input)
if err != nil {
return err
}
_ = output
}
// Login
{
input := &LoginRequest{
Email: email,
Password: password,
}
output, err := api.Login(input)
if err != nil {
return err
}
api.SetToken(output.Token)
}
return nil
}