From 8845bcaf531b30f4c6bbd358f97e35718332dfad Mon Sep 17 00:00:00 2001 From: Chad Brokaw <36685920+chadbrokaw@users.noreply.github.com> Date: Mon, 16 Dec 2024 10:46:04 -0700 Subject: [PATCH] feat: reset password api --- .../__tests__/api/authApiService.test.ts | 16 ++++++++++++++++ app/javascript/api/authApiService.ts | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/app/javascript/__tests__/api/authApiService.test.ts b/app/javascript/__tests__/api/authApiService.test.ts index dfd9a2b3d..64f9cc664 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 82300255d..89f1a4ff0 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