Skip to content

Commit

Permalink
feat: reset password api
Browse files Browse the repository at this point in the history
  • Loading branch information
chadbrokaw committed Dec 16, 2024
1 parent 21e6f4d commit 1336128
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/javascript/__tests__/api/authApiService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
updatePassword,
getApplications,
deleteApplication,
resetPassword,
} from "../../api/authApiService"

jest.mock("axios")
Expand Down Expand Up @@ -100,6 +101,21 @@ describe("authApiService", () => {
})
})

describe("resetPassword", () => {
it("calls apiService put", async () => {
const url = "/api/v1/auth/password"
const newPassword = "abc123"
await resetPassword(newPassword)
expect(authenticatedPut).toHaveBeenCalledWith(
url,
expect.objectContaining({
password: newPassword,
password_confirmation: newPassword,
})
)
})
})

describe("updatePassword", () => {
it("calls apiService put", async () => {
const url = "/api/v1/auth/password"
Expand Down
7 changes: 7 additions & 0 deletions app/javascript/api/authApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ export const updateEmail = async (email: string): Promise<string> =>
},
}).then(({ data }) => data.status)

export const resetPassword = async (new_password: string): Promise<string> =>
authenticatedPut<{ message: string }>("/api/v1/auth/password", {
password: new_password,
password_confirmation: new_password,
locale: getRoutePrefix(window.location.pathname) || LanguagePrefix.English,
}).then(({ data }) => data.message)

export const updatePassword = async (
new_password: string,
current_password: string
Expand Down

0 comments on commit 1336128

Please sign in to comment.