-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rujic/feature/add-list-users-with-email-fi…
…lter Add V2 List Users API
- Loading branch information
Showing
2 changed files
with
171 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,10 +40,6 @@ func TestCreateUser(t *testing.T) { | |
t.Fatal(err) | ||
} | ||
|
||
// Note, the response here doesn't reflect some of the values we would really expect | ||
// this is because they are not part of the response from the API and in parsing the JSON | ||
// if a value is missing golang will use the "empty value". | ||
// The actual Use | ||
want := &User{ | ||
FirstName: "test", | ||
LastName: "user", | ||
|
@@ -129,3 +125,130 @@ func TestCreateUserInvalidResponse(t *testing.T) { | |
t.Errorf("expected CreateUser to error out on an invalid response from the server") | ||
} | ||
} | ||
|
||
func TestGetAllUsersV2(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
testMux.HandleFunc("/api-public/v2/user", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "GET") | ||
w.Write([]byte(`{ | ||
"users": [ | ||
{ | ||
"firstName": "test", | ||
"lastName": "user", | ||
"displayName": "test user", | ||
"username": "go_testuser", | ||
"email": "[email protected]", | ||
"createdAt": "2018-06-16T01:19:39Z", | ||
"passwordLastUpdated": "2018-07-16T22:48:01Z", | ||
"verified": true, | ||
"_selfUrl": "/api-public/v1/user/go_testuser" | ||
} | ||
] | ||
}`)) | ||
}) | ||
|
||
resp, _, err := testClient.GetAllUserV2() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
user := User{ | ||
FirstName: "test", | ||
LastName: "user", | ||
Username: "go_testuser", | ||
Email: "[email protected]", | ||
CreatedAt: "2018-06-16T01:19:39Z", | ||
PasswordLastUpdated: "2018-07-16T22:48:01Z", | ||
Verified: true, | ||
} | ||
|
||
expected := &UserListV2{ | ||
Users: []User{user}, | ||
} | ||
|
||
if !reflect.DeepEqual(resp, expected) { | ||
t.Errorf("returned \n\n%#v want \n\n%#v", resp, expected) | ||
} | ||
} | ||
|
||
func TestGetAllUsersV2WrongFormat(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
testMux.HandleFunc("/api-public/v2/user", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "GET") | ||
w.Write([]byte(`{ | ||
"users": [ | ||
[ | ||
{ | ||
"firstName": "test", | ||
"lastName": "user", | ||
"displayName": "test user", | ||
"username": "go_testuser", | ||
"email": "[email protected]", | ||
"createdAt": "2018-06-16T01:19:39Z", | ||
"passwordLastUpdated": "2018-07-16T22:48:01Z", | ||
"verified": true, | ||
"_selfUrl": "/api-public/v2/user/go_testuser" | ||
} | ||
] | ||
] | ||
}`)) | ||
}) | ||
|
||
resp, _, err := testClient.GetAllUserV2() | ||
if err == nil { | ||
t.Fatal(err) | ||
} | ||
if resp != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestGetUsersByEmailV2(t *testing.T) { | ||
setup() | ||
defer teardown() | ||
|
||
testEmail := "[email protected]" | ||
testMux.HandleFunc("/api-public/v2/user", func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, "GET") | ||
w.Write([]byte(`{ | ||
"users": [ | ||
{ | ||
"firstName": "test", | ||
"lastName": "user", | ||
"displayName": "test user", | ||
"username": "go_testuser", | ||
"email": "[email protected]", | ||
"createdAt": "2018-06-16T01:19:39Z", | ||
"passwordLastUpdated": "2018-07-16T22:48:01Z", | ||
"verified": true, | ||
"_selfUrl": "/api-public/v2/user/go_testuser" | ||
} | ||
] | ||
}`)) | ||
}) | ||
|
||
resp, _, err := testClient.GetUserByEmail(testEmail) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
user := User{ | ||
FirstName: "test", | ||
LastName: "user", | ||
Username: "go_testuser", | ||
Email: testEmail, | ||
CreatedAt: "2018-06-16T01:19:39Z", | ||
PasswordLastUpdated: "2018-07-16T22:48:01Z", | ||
Verified: true, | ||
} | ||
|
||
expected := &UserListV2{ | ||
Users: []User{user}, | ||
} | ||
|
||
if !reflect.DeepEqual(resp, expected) { | ||
t.Errorf("returned \n\n%#v want \n\n%#v", resp, expected) | ||
} | ||
} |