-
Notifications
You must be signed in to change notification settings - Fork 0
/
users_test.go
69 lines (56 loc) · 1.65 KB
/
users_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
package main_test
import (
"testing"
"piot-server"
)
func TestFindUserByNotExistingEmail(t *testing.T) {
db := GetDb(t)
log := GetLogger(t)
users := main.NewUsers(log, db)
CleanDb(t, db)
_, err := users.FindByEmail("xx")
Assert(t, err != nil, "User shall not be found")
}
func TestFindUserByExistingEmail(t *testing.T) {
db := GetDb(t)
log := GetLogger(t)
users := main.NewUsers(log, db)
CleanDb(t, db)
userId := CreateUser(t, db, "test1@com", "pass")
orgId := CreateOrg(t, db, "testorg")
AddOrgUser(t, db, orgId, userId)
user, err := users.FindByEmail("test1@com")
Ok(t, err)
Equals(t, "test1@com", user.Email)
Equals(t, 1, len(user.Orgs))
Equals(t, "testorg", user.Orgs[0].Name)
}
func TestGetAdmins(t *testing.T) {
db := GetDb(t)
log := GetLogger(t)
users := main.NewUsers(log, db)
CleanDb(t, db)
CreateUser(t, db, "test1@com", "pass")
CreateUser(t, db, "test2@com", "pass2")
CreateAdmin(t, db, "admin1@com", "admpass1")
CreateAdmin(t, db, "admin2@com", "admpass2")
admins, err := users.GetAdmins()
Ok(t, err)
Equals(t, 2, len(admins))
Equals(t, "admin1@com", admins[0].Email)
Equals(t, "admin2@com", admins[1].Email)
}
func TestCreateUser(t *testing.T) {
db := GetDb(t)
log := GetLogger(t)
users := main.NewUsers(log, db)
CleanDb(t, db)
user, err := users.Create("[email protected]", "pass")
Ok(t, err)
//compare ids
userRead, err := users.FindByEmail("[email protected]")
Ok(t, err)
Equals(t, user.Id, userRead.Id)
Equals(t, "[email protected]", userRead.Email)
Equals(t, 0, len(userRead.Orgs))
}