From 673d29610986f18f674537e932ea1d9bc8fca4b4 Mon Sep 17 00:00:00 2001 From: Emma Mansell <73774046+7emansell@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:44:59 -0500 Subject: [PATCH] One more test --- src/server/tests/helpers.test.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/server/tests/helpers.test.ts b/src/server/tests/helpers.test.ts index 67b1c9c7b..92a63fb49 100644 --- a/src/server/tests/helpers.test.ts +++ b/src/server/tests/helpers.test.ts @@ -348,6 +348,35 @@ describe("updateUsername", () => { expect(response.status).toBe(200) expect(response.message).toBe("Username taken") }) + + it("should return an error if there's a server error", async () => { + const newUsername = "newUsername" + const patronId = "678910" + + const platformMethodMock = jest.fn().mockResolvedValueOnce({ + status: 502, + type: "ils-integration-error", + }) + ;(nyplApiClient as jest.Mock).mockResolvedValueOnce({ + post: platformMethodMock, + }) + + const response = await updateUsername(patronId, newUsername) + + expect(nyplApiClient).toHaveBeenCalled + expect(platformMethodMock).toHaveBeenNthCalledWith( + 1, + "/validations/username", + { + username: newUsername, + } + ) + + expect(sierraClient).not.toHaveBeenCalled + + expect(response.status).toBe(500) + expect(response.message).toBe("Username update failed") + }) }) describe("renewCheckout", () => {