diff --git a/app/javascript/__tests__/api/authApiService.test.ts b/app/javascript/__tests__/api/authApiService.test.ts index dfd9a2b3d3..64f9cc6645 100644 --- a/app/javascript/__tests__/api/authApiService.test.ts +++ b/app/javascript/__tests__/api/authApiService.test.ts @@ -14,6 +14,7 @@ import { updatePassword, getApplications, deleteApplication, + resetPassword, } from "../../api/authApiService" jest.mock("axios") @@ -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" diff --git a/app/javascript/api/authApiService.ts b/app/javascript/api/authApiService.ts index 82300255da..89f1a4ff02 100644 --- a/app/javascript/api/authApiService.ts +++ b/app/javascript/api/authApiService.ts @@ -83,6 +83,13 @@ export const updateEmail = async (email: string): Promise => }, }).then(({ data }) => data.status) +export const resetPassword = async (new_password: string): Promise => + 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