-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathservice_test.go
90 lines (80 loc) · 2.14 KB
/
service_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package sso_test
import (
"github.com/stretchr/testify/assert"
"github.com/viant/dsc"
"github.com/viant/endly/example/ui/sso"
"github.com/viant/toolbox"
"log"
"net/http"
"path"
"testing"
)
func TestService_SignIn(t *testing.T) {
var dataFileBaseDir = path.Join(toolbox.CallerDirectory(3), "test/data")
var dataFile = path.Join(dataFileBaseDir, "users.json")
toolbox.RemoveFileIfExist(dataFile)
dsConfig := dsc.NewConfig("ndjson", "[url]", "dateFormat:yyyy-MM-dd hh:mm:ss,ext:json,url:"+toolbox.FileSchema+dataFileBaseDir)
config := &sso.Config{
Port: "8871",
StaticRoutes: []*sso.StaticRoute{
{
URI: "/signup/",
Directory: "static/",
},
{
URI: "/signin/",
Directory: "static/",
},
},
DsConfig: dsConfig,
}
service, err := sso.NewService(config)
if err != nil {
log.Fatal(err)
}
{ //test singin with non existing users
response := service.SignIn(&sso.SignInRequest{
Email: "[email protected]",
Password: "abc",
})
assert.Equal(t, "unable to find a user for provided credentials", response.Error)
}
{
response := service.SignUp(&sso.SignUpRequest{
User: &sso.User{
Email: "[email protected]",
Name: "abc",
},
Password: "abc",
DataOfBirth: "2002-02-11",
}, &http.Request{RemoteAddr: "127.0.0.1"})
assert.EqualValues(t, "", response.Error)
assert.NotNil(t, response.User.DateOfBirth)
}
{ // try again register the same user
response := service.SignUp(&sso.SignUpRequest{
User: &sso.User{
Email: "[email protected]",
Name: "abc",
},
Password: "abc",
DataOfBirth: "2002-02-11",
}, &http.Request{RemoteAddr: "127.0.0.1"})
assert.EqualValues(t, "email [email protected] has been already registered", response.Error)
}
{ //test singin with existing users
response := service.SignIn(&sso.SignInRequest{
Email: "[email protected]",
Password: "abc",
})
assert.Equal(t, "", response.Error)
assert.NotNil(t, response.User)
}
{ //test singin with invalid credentials users
response := service.SignIn(&sso.SignInRequest{
Email: "[email protected]",
Password: "abc1",
})
assert.Equal(t, "unable to find a user for provided credentials", response.Error)
}
}