tsk-30: Update password (#33)
Closes #30 Reviewed-on: phoenix/textsender-auth#33 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -13,7 +13,6 @@ import (
|
||||
|
||||
"git.kundeng.us/phoenix/textsender-auth/internal/handler/endpoint"
|
||||
"git.kundeng.us/phoenix/textsender-auth/internal/store/mock"
|
||||
"git.kundeng.us/phoenix/textsender-auth/internal/utility"
|
||||
)
|
||||
|
||||
func TestLogin(t *testing.T) {
|
||||
@@ -21,20 +20,13 @@ func TestLogin(t *testing.T) {
|
||||
mockstore := mock.NewMockUserStore()
|
||||
handler := NewLoginHandler(cfg, mockstore)
|
||||
|
||||
testUser := GetTestUser()
|
||||
unhashedPassword := testUser.Password
|
||||
hashing := utility.HashMash{Password: testUser.Password}
|
||||
hashedPassword, err := hashing.HashPassword()
|
||||
assert.NoError(t, err)
|
||||
|
||||
testUser.Password = hashedPassword
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
mockstore.CreateUser(ctx, &testUser)
|
||||
testUser, unhashedPassword, err := createUser(ctx, mockstore)
|
||||
assert.NoError(t, err, "Error Creating user")
|
||||
|
||||
loginUser := LoginAccount{Username: testUser.Username, Password: unhashedPassword}
|
||||
loginUser := LoginAccount{Username: testUser.Username, Password: *unhashedPassword}
|
||||
jsonValue, _ := json.Marshal(loginUser)
|
||||
|
||||
req, _ := http.NewRequest("POST", endpoint.Login, strings.NewReader(string(jsonValue)))
|
||||
@@ -50,3 +42,29 @@ func TestLogin(t *testing.T) {
|
||||
|
||||
assert.NotEmpty(t, response.Data, "An access token should have been returned")
|
||||
}
|
||||
|
||||
func TestUpdatePassword(t *testing.T) {
|
||||
cfg := GetConfig()
|
||||
mockstore := mock.NewMockUserStore()
|
||||
handler := NewLoginHandler(cfg, mockstore)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
testUser, unhashedPassword, err := createUser(ctx, mockstore)
|
||||
assert.NoError(t, err, "Error Creating user")
|
||||
assert.NotNil(t, testUser, "User should not be nil")
|
||||
|
||||
updatedPassword := "TakeATrip2yonder!"
|
||||
newPassword := UpdatePasswordRequest{UserId: testUser.Id, CurrentPassword: *unhashedPassword, UpdatedPassword: updatedPassword, ConfirmedPassword: updatedPassword}
|
||||
jsonValue, _ := json.Marshal(newPassword)
|
||||
|
||||
req, _ := http.NewRequest("PATCH", endpoint.UpdatePassword, strings.NewReader(string(jsonValue)))
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handler.UpdatePassword(rr, req)
|
||||
assert.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
var response UpdatePasswordResponse
|
||||
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user