Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chadbrokaw committed Jan 24, 2025
1 parent beb38fe commit a228ea6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/account/AccountService.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/javascript/__tests__/__util__/accountUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { User } from "../../authentication/user"

export const mockProfileStub: User = {
uid: "abc123",
id: 20,
email: "[email protected]",
created_at: new Date(),
updated_at: new Date(),
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/__tests__/api/apiService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ 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(
<UserProvider>
<TestComponent />
</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 () => {
Expand Down

0 comments on commit a228ea6

Please sign in to comment.