-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
model refactor and user relation complete
- Loading branch information
1 parent
01d6d50
commit cbb0540
Showing
7 changed files
with
563 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ func TestCreateUser(t *testing.T) { | |
"phone": "+1234567890", | ||
"image": "https://example.com/avatar.png" | ||
}` | ||
TestPostRequest(t, userData, "/api/signup", 201, "User created successfully") | ||
TestPostRequest(t, userData, "/api/signup", 201, "User created successfully", true) | ||
} | ||
|
||
func TestDuplicateUserError(t *testing.T) { | ||
|
@@ -26,8 +26,7 @@ func TestDuplicateUserError(t *testing.T) { | |
"phone": "+1234567890", | ||
"image": "https://example.com/avatar.png" | ||
}` | ||
TestPostRequest(t, userData, "/api/signup", http.StatusForbidden, "User with given user name or email or phone already exist") | ||
|
||
TestPostRequest(t, userData, "/api/signup", http.StatusForbidden, "User with given user name or email or phone already exist", true) | ||
} | ||
func TestMissingFieldErrorSignup(t *testing.T) { | ||
userData := `{ | ||
|
@@ -37,39 +36,75 @@ func TestMissingFieldErrorSignup(t *testing.T) { | |
"phone": "+1234567892", | ||
"image": "https://example.com/avatar.png" | ||
}` | ||
TestPostRequest(t, userData, "/api/signup", 500, "Missing field") | ||
TestPostRequest(t, userData, "/api/signup", 500, "Missing field", true) | ||
} | ||
|
||
//signin | ||
|
||
func TestLoginUser(t *testing.T) { | ||
userData := `{ | ||
"username": "test_user", | ||
"password": "password" | ||
"password": "password" | ||
}` | ||
TestPostRequest(t, userData, "/api/signin", 200, "Login successfull") | ||
|
||
TestPostRequest(t, userData, "/api/signin", 200, "Login successfull", true) | ||
} | ||
|
||
func TestIncorrectPasswordError(t *testing.T) { | ||
userData := `{ | ||
"username": "test_user", | ||
"password": "incorrect" | ||
}` | ||
TestPostRequest(t, userData, "/api/signin", 403, "Incorrect Password") | ||
TestPostRequest(t, userData, "/api/signin", 403, "Incorrect Password", true) | ||
|
||
} | ||
func TestNoUserErrorSignin(t *testing.T) { | ||
userData := `{ | ||
"username": "test_user_not_found", | ||
"password": "password" | ||
}` | ||
TestPostRequest(t, userData, "/api/signin", 404, "User not found") | ||
TestPostRequest(t, userData, "/api/signin", 404, "User not found", true) | ||
} | ||
|
||
func TestMissingFieldErrorSignin(t *testing.T) { | ||
userData := `{ | ||
"username": "test_user" | ||
}` | ||
TestPostRequest(t, userData, "/api/signin", 500, "Field not found") | ||
TestPostRequest(t, userData, "/api/signin", 500, "Field not found", true) | ||
} | ||
|
||
func TestCreateOtherUsers(t *testing.T) { | ||
userData := `{ | ||
"username": "related_user", | ||
"name": "related_user", | ||
"email": "[email protected]", | ||
"password": "password", | ||
"phone": "+1234557890", | ||
"image": "https://example.com/avatar.png" | ||
}` | ||
TestPostRequest(t, userData, "/api/signup", 201, "User created successfully", true) | ||
userData2 := `{ | ||
"username": "not_allowed_user", | ||
"name": "not_allowed_user", | ||
"email": "[email protected]", | ||
"password": "password", | ||
"phone": "+1234457890", | ||
"image": "https://example.com/avatar.png" | ||
}` | ||
TestPostRequest(t, userData2, "/api/signup", 201, "User created successfully", true) | ||
} | ||
|
||
// logged in related user | ||
func TestLoginRelatedUserUsingEmail(t *testing.T) { | ||
userData := `{ | ||
"email": "[email protected]", | ||
"password": "password" | ||
}` | ||
TestPostRequest(t, userData, "/api/signin", 200, "Login successfull", true) | ||
} | ||
func TestLoginNotAllowedUserUsingPhone(t *testing.T) { | ||
userData := `{ | ||
"phone": "+1234457890", | ||
"password": "password" | ||
}` | ||
TestPostRequest(t, userData, "/api/signin", 200, "Login successfull", true) | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.