-
Notifications
You must be signed in to change notification settings - Fork 2
/
login.go
48 lines (39 loc) 路 1.11 KB
/
login.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
package dismock
import (
"net/http"
"testing"
"github.com/diamondburned/arikawa/api"
"github.com/mavolin/dismock/internal/mockutil"
)
type loginPayload struct {
Email string `json:"email"`
Password string `json:"password"`
}
// Login mocks a Login request.
func (m *Mocker) Login(email, password string, response api.LoginResponse) {
m.MockAPI("Login", http.MethodPost, "/auth/login",
func(w http.ResponseWriter, r *http.Request, t *testing.T) {
expect := loginPayload{
Email: email,
Password: password,
}
mockutil.CheckJSON(t, r.Body, new(loginPayload), &expect)
mockutil.WriteJSON(t, w, response)
})
}
type totpPayload struct {
Code string `json:"code"`
Ticket string `json:"ticket"`
}
// TOTP mocks a TOTP request.
func (m *Mocker) TOTP(code, ticket string, response api.LoginResponse) {
m.MockAPI("TOTP", http.MethodPost, "/auth/mfa/totp",
func(w http.ResponseWriter, r *http.Request, t *testing.T) {
expect := totpPayload{
Code: code,
Ticket: ticket,
}
mockutil.CheckJSON(t, r.Body, new(totpPayload), &expect)
mockutil.WriteJSON(t, w, response)
})
}