-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuser_test.go
39 lines (36 loc) · 1.41 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
package wallabago
import (
"testing"
"time"
)
func TestUser(t *testing.T) {
expected := LoggedInUser{
ID: 1,
UserName: "john",
Email: "[email protected]",
CreatedAt: &WallabagTime{time.Date(2011, 1, 1, 21, 31, 5, 0, time.FixedZone("+0000", 0))},
UpdatedAt: &WallabagTime{time.Date(2024, 2, 1, 16, 16, 17, 0, time.FixedZone("+0000", 0))},
}
got, _ := User(mockGetBodyOfUserApiCall)
if expected.ID != got.ID {
t.Errorf("expected ID %v but got %v", expected.ID, got.ID)
}
if expected.UserName != got.UserName {
t.Errorf("expected UserName %v but got %v", expected.UserName, got.UserName)
}
if expected.Email != got.Email {
t.Errorf("expected Email %v but got %v", expected.Email, got.Email)
}
if !expected.CreatedAt.Equal(got.CreatedAt) {
t.Errorf("expected CreatedAt:\n%v\nbut got:\n%v", expected.CreatedAt, got.CreatedAt)
}
if !expected.UpdatedAt.Equal(got.UpdatedAt) {
t.Errorf("expected UpdatedAt:\n%v\nbut got:\n%v", expected.UpdatedAt, got.UpdatedAt)
}
if expected.CreatedAt.Equal(got.UpdatedAt) {
t.Errorf("expected CreatedAt:\n%v\nto be different than UpdatedAt but it's equal:\n%v", expected.CreatedAt, got.UpdatedAt)
}
}
func mockGetBodyOfUserApiCall(url string, httpMethod string, postData []byte) ([]byte, error) {
return []byte(`{"id":1,"username":"john","email":"[email protected]","created_at":"2011-01-01T21:31:05+0000","updated_at":"2024-02-01T16:16:17+0000"}`), nil
}