From a228ea689a3015f585f7fb410c2add28111c472b Mon Sep 17 00:00:00 2001 From: Chad Brokaw <36685920+chadbrokaw@users.noreply.github.com> Date: Wed, 22 Jan 2025 14:44:11 -0700 Subject: [PATCH] fix: tests --- app/assets/javascripts/account/AccountService.js.coffee | 2 +- app/javascript/__tests__/__util__/accountUtils.tsx | 1 + app/javascript/__tests__/api/apiService.test.ts | 3 ++- .../__tests__/authentication/context/UserProvider.test.tsx | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/account/AccountService.js.coffee b/app/assets/javascripts/account/AccountService.js.coffee index e39c67752d..49bb3637ff 100644 --- a/app/assets/javascripts/account/AccountService.js.coffee +++ b/app/assets/javascripts/account/AccountService.js.coffee @@ -153,7 +153,7 @@ AccountService = ( # reset the user data immediately, then call signOut Service.setLoggedInUser({}) ShortFormApplicationService.resetApplicationData() unless opts.preserveAppData - AnalyticsService.trackEvent('sign_out', { origin: opts.origin || 'Sign Out' }) + AnalyticsService.trackEvent('logout', {reason: "Angular logout"}) $auth.signOut() # close any open modal, e.g. "Lottery Results" that may have been opened while # you were on My Applications diff --git a/app/javascript/__tests__/__util__/accountUtils.tsx b/app/javascript/__tests__/__util__/accountUtils.tsx index acee3844d7..2aafd23cf2 100644 --- a/app/javascript/__tests__/__util__/accountUtils.tsx +++ b/app/javascript/__tests__/__util__/accountUtils.tsx @@ -4,6 +4,7 @@ import { User } from "../../authentication/user" export const mockProfileStub: User = { uid: "abc123", + id: 20, email: "email@email.com", created_at: new Date(), updated_at: new Date(), diff --git a/app/javascript/__tests__/api/apiService.test.ts b/app/javascript/__tests__/api/apiService.test.ts index 1a2e318e8c..e947c42f1f 100644 --- a/app/javascript/__tests__/api/apiService.test.ts +++ b/app/javascript/__tests__/api/apiService.test.ts @@ -14,7 +14,8 @@ import { jest.mock("axios") // mock getStorage function from `authentication/token.ts' -Storage.prototype.getItem = (_key: string) => JSON.stringify({ "access-token": "test-token" }) +Storage.prototype.getItem = (_key: string) => + JSON.stringify({ "access-token": "test-token", expiry: Date.now() / 1000 + 3600 }) describe("apiService", () => { const url = "test-url" diff --git a/app/javascript/__tests__/authentication/context/UserProvider.test.tsx b/app/javascript/__tests__/authentication/context/UserProvider.test.tsx index 0838251b59..f2a7a3fb4f 100644 --- a/app/javascript/__tests__/authentication/context/UserProvider.test.tsx +++ b/app/javascript/__tests__/authentication/context/UserProvider.test.tsx @@ -101,7 +101,7 @@ describe("UserProvider", () => { it("should handle token invalidation on initial load", async () => { ;(isTokenValid as jest.Mock).mockReturnValue(false) - ;(getProfile as jest.Mock).mockResolvedValue(mockProfileStub) + ;(getProfile as jest.Mock).mockRejectedValueOnce(new Error("Token expired")) await renderAndLoadAsync( @@ -109,7 +109,7 @@ describe("UserProvider", () => { ) - expect(screen.getByText("Initial state loaded")).not.toBeNull() + await waitFor(() => expect(screen.getByText("Initial state loaded")).not.toBeNull()) }) it("should handle temporary auth params from URL", async () => {