-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Beregner tid for utloggingsvarsel basert på `expires_in_seconds` og regner om dette til lokal tid. Dermed slipper vi problemer hvor brukere har feil klokkeslett på maskinen sin. Rydder i logout-warning for bedre lesbarhet. Skriver enhetstester for auth-hjelperen. Flytter også logout-warning ut av controller-mappe (som den eneste komponenten der) og legger den i src sammen med de andre. Foreslår å bumpe vitest fordi gammel versjon ikke fungerer med VS-code. --------- Co-authored-by: Andreas Nordahl <[email protected]>
- Loading branch information
1 parent
a8c63cd
commit bd2d031
Showing
10 changed files
with
459 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { SessionData, transformSessionToAuth } from "./auth"; | ||
|
||
describe("Auth helpers", () => { | ||
describe("transformSessionToAuth", () => { | ||
it("correctly uses expire_in_seconds when transforming to local time", () => { | ||
const mockCurrentISODate = "2021-10-10T10:10:00.000Z"; | ||
|
||
// Note: Discrepancy between ISO dates and ends_in_seconds and expire_in_seconds | ||
// This is intentional to test that the function does infact use the seconds and not the time stamps. | ||
const mockSessionData: SessionData = { | ||
session: { | ||
created_at: "2021-10-10T10:00:00.000Z", | ||
ends_at: "2021-10-10T16:00:00.000Z", | ||
timeout_at: "2021-10-10T16:00:00.000Z", | ||
ends_in_seconds: 3600, | ||
active: true, | ||
timeout_in_seconds: 3600, | ||
}, | ||
tokens: { | ||
expire_at: "2021-10-10T11:05:00.000Z", | ||
refreshed_at: "2021-10-10T12:05:00.000Z", | ||
expire_in_seconds: 1800, | ||
next_auto_refresh_in_seconds: 1800, | ||
refresh_cooldown: false, | ||
refresh_cooldown_seconds: 0, | ||
}, | ||
}; | ||
|
||
vi.useFakeTimers(); | ||
vi.setSystemTime(mockCurrentISODate); | ||
|
||
const authData = transformSessionToAuth(mockSessionData); | ||
|
||
expect(authData.sessionExpireAtLocal).toBe( | ||
"2021-10-10T11:10:00.000Z", | ||
); | ||
expect(authData.tokenExpireAtLocal).toBe( | ||
"2021-10-10T10:40:00.000Z", | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.