-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_test.go
50 lines (35 loc) · 1.19 KB
/
user_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
package mailinabox
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestUserService_Login(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/admin/login", testHandler("user/login.json", http.MethodGet, http.StatusOK))
names, err := client.User.Login(context.Background())
require.NoError(t, err)
expected := &Session{
APIKey: "1a2b3c4d5e6f7g8h9i0j",
Email: "user@example.com",
Privileges: []string{"admin"},
Status: "ok",
}
assert.Equal(t, expected, names)
}
func TestUserService_Login_error(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/admin/login", testHandler("user/login_error.json", http.MethodGet, http.StatusOK))
_, err := client.User.Login(context.Background())
require.EqualError(t, err, "invalid: Incorrect username or password")
}
func TestUserService_Logout(t *testing.T) {
client, mux := setupTest(t)
mux.HandleFunc("/admin/logout", testHandler("user/logout.json", http.MethodPost, http.StatusOK))
names, err := client.User.Logout(context.Background())
require.NoError(t, err)
expected := &Session{Status: "ok"}
assert.Equal(t, expected, names)
}