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
/
Copy pathmembership_test.go
65 lines (53 loc) · 1.67 KB
/
membership_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
package staticbackend
import (
"fmt"
"strings"
"testing"
"github.com/staticbackendhq/core/model"
)
func TestGetCurrentAuthUser(t *testing.T) {
resp := dbReq(t, mship.me, "GET", "/me", nil)
defer resp.Body.Close()
if resp.StatusCode > 299 {
t.Fatal(GetResponseBody(t, resp))
}
var me model.Auth
if err := parseBody(resp.Body, &me); err != nil {
t.Fatal(err)
} else if !strings.EqualFold(me.Email, admEmail) {
t.Errorf("expected email to be %s got %s", admEmail, me.Email)
} else if me.Role != 100 {
t.Errorf("expected role to be 100 got %d", me.Role)
}
}
func TestMagicLink(t *testing.T) {
// note, even though the magic link route allow public (un-unthenticated) req
// I'm using dbReq (which enforce the stdauth) for ease of re-using the
// function.
data := new(struct {
FromEmail string `json:"fromEmail"`
FromName string `json:"fromName"`
Email string `json:"email"`
Subject string `json:"subject"`
Body string `json:"body"`
MagicLink string `json:"link"`
})
data.FromEmail = "[email protected]"
data.FromName = "unit test"
data.Email = admEmail
data.Subject = "Magic link from unit test"
data.Body = "<p>Hello</p><p>Please click on the following link to sign-in</p><p>[ink]</p>"
data.MagicLink = "https://mycustom.link/with-code"
resp := dbReq(t, mship.magicLink, "POST", "/login/magic", data)
defer resp.Body.Close()
if resp.StatusCode > 299 {
t.Fatal(GetResponseBody(t, resp))
}
// in dev mode, the code is always 666333
u := fmt.Sprintf("/login/magic?email=%s&code=666333", admEmail)
resp2 := dbReq(t, mship.magicLink, "GET", u, nil)
defer resp2.Body.Close()
if resp2.StatusCode > 299 {
t.Fatal(GetResponseBody(t, resp2))
}
}