-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcontroller_account_test.go
61 lines (47 loc) · 1.53 KB
/
controller_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
package tests
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/twreporter/go-api/models"
"github.com/twreporter/go-api/storage"
)
func TestSignIn(t *testing.T) {
// TODO: Test for SignInV2
}
func TestActivate(t *testing.T) {
var resp *httptest.ResponseRecorder
// START - test activate endpoint //
user := getReporterAccount(Globs.Defaults.Account)
// Renew token for v2 endpoint validation
activateToken := "Activate_Token_2"
expTime := time.Now().Add(time.Duration(15) * time.Minute)
as := storage.NewGormStorage(Globs.GormDB)
if err := as.UpdateReporterAccount(models.ReporterAccount{
ID: user.ID,
ActivateToken: activateToken,
ActExpTime: expTime,
}); nil != err {
fmt.Println(err.Error())
}
// START - test activate endpoint v2//
// test activate
resp = serveHTTP("GET", fmt.Sprintf("/v2/auth/activate?email=%v&token=%v", Globs.Defaults.Account, activateToken), "", "", "")
fmt.Print(resp.Body)
// validate status code
assert.Equal(t, http.StatusTemporaryRedirect, resp.Code)
cookies := resp.Result().Cookies()
cookieMap := make(map[string]http.Cookie)
for _, cookie := range cookies {
cookieMap[cookie.Name] = *cookie
}
// validate Set-Cookie header
assert.Contains(t, cookieMap, "id_token")
// test activate fails
resp = serveHTTP("GET", fmt.Sprintf("/v2/auth/activate?email=%v&token=%v", Globs.Defaults.Account, ""), "", "", "")
assert.Equal(t, http.StatusTemporaryRedirect, resp.Code)
// END - test activate endpoint v2//
}