| 1 | import { describe, expect, it } from "bun:test"; |
| 2 | |
| 3 | import { shouldRedirectToSignIn } |
| 4 | |
| 5 | describe("shouldRedirectToSignIn", () |
| 6 | it("waits out a refetch instead of bouncing on a stale null", |
| 7 | expect( |
| 8 | shouldRedirectToSignIn({ |
| 9 | data: null, |
| 10 | isPending: false, |
| 11 | isFetching: true, |
| 12 | }), |
| 13 | ).toBe(false); |
| 14 | }); |
| 15 | |
| 16 | it("redirects once the session is settled and empty", |
| 17 | expect( |
| 18 | shouldRedirectToSignIn({ |
| 19 | data: null, |
| 20 | isPending: false, |
| 21 | isFetching: false, |
| 22 | }), |
| 23 | ).toBe(true); |
| 24 | }); |
| 25 | |
| 26 | it("stays put with a session, and while the first fetch is pending", |
| 27 | expect( |
| 28 | shouldRedirectToSignIn({ |
| 29 | data: { user: {} |
| 30 | isPending: false, |
| 31 | isFetching: false, |
| 32 | }), |
| 33 | ).toBe(false); |
| 34 | expect( |
| 35 | shouldRedirectToSignIn({ data: |
| 36 | ).toBe(false); |
| 37 | }); |
| 38 | }); |