This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
account_test.go
76 lines (61 loc) · 1.66 KB
/
account_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
package staticbackend
import (
"testing"
"time"
"github.com/staticbackendhq/core/backend"
"github.com/staticbackendhq/core/model"
)
func TestUserAddRemoveFromAccount(t *testing.T) {
u := model.Login{Email: "[email protected]", Password: "newuser1234"}
resp := dbReq(t, acct.addUser, "POST", "/account/users", u)
defer resp.Body.Close()
if resp.StatusCode > 299 {
t.Fatal(GetResponseBody(t, resp))
}
// adding user with same email should return an error
resp2 := dbReq(t, acct.addUser, "POST", "/account/users", u)
defer resp2.Body.Close()
if resp2.StatusCode <= 299 {
t.Fatal(GetResponseBody(t, resp2))
}
// check if users is created
users, err := backend.DB.ListUsers(dbName, testAccountID)
if err != nil {
t.Fatal(err)
}
newUserID := ""
for _, user := range users {
if user.Email == "[email protected]" {
newUserID = user.ID
if user.Created.Format("2006-01-02") != time.Now().Format("2006-01-02") {
t.Errorf("expected user to have a recent creation date, got %v", user.Created)
}
break
}
}
if len(newUserID) == 0 {
t.Fatal("unable to find new user")
}
resp3 := dbReq(t, acct.deleteUser, "DELETE", "/account/users/"+newUserID, nil)
defer resp3.Body.Close()
if resp3.StatusCode > 299 {
t.Fatal(GetResponseBody(t, resp3))
}
users, err = backend.DB.ListUsers(dbName, testAccountID)
if err != nil {
t.Fatal(err)
}
for _, user := range users {
if user.ID == newUserID {
t.Fatal("deleted user was found?")
break
}
}
}
func TestAddNewDatabase(t *testing.T) {
resp := dbReq(t, acct.addDatabase, "GET", "/account/add-db", nil)
defer resp.Body.Close()
if resp.StatusCode > 299 {
t.Fatal(GetResponseBody(t, resp))
}
}