|
| 1 | +import { vi, expect, it, describe, beforeEach } from "vitest" |
| 2 | +import renderPage from "../src/lib/pages/index" |
| 3 | +import { authOptions } from "./fixtures/pages" |
| 4 | +import { init } from "../src/lib/init" |
| 5 | + |
| 6 | +describe("pages", () => { |
| 7 | + describe("sign-out", () => { |
| 8 | + beforeEach(() => { |
| 9 | + vi.resetAllMocks() |
| 10 | + }) |
| 11 | + |
| 12 | + it("should attempt to render signout page", async () => { |
| 13 | + // Generated when visiting `/auth/signout` |
| 14 | + const { options } = await init({ |
| 15 | + authOptions, |
| 16 | + action: "signout", |
| 17 | + providerId: "github", |
| 18 | + url: new URL("http://localhost:3000/auth/signout"), |
| 19 | + cookies: {}, |
| 20 | + isPost: true, |
| 21 | + csrfDisabled: true, |
| 22 | + }) |
| 23 | + |
| 24 | + const render = renderPage({ ...options, query: {}, cookies: [] }) |
| 25 | + const signOutPage = render.signout() |
| 26 | + |
| 27 | + expect(signOutPage.body).toContain(`<title>Sign Out</title>`) |
| 28 | + expect(signOutPage.body).toContain( |
| 29 | + `action="http://localhost:3000/auth/signout"` |
| 30 | + ) |
| 31 | + }) |
| 32 | + |
| 33 | + it("should return correct URL for signout page form action", async () => { |
| 34 | + // When visiting `/auth/signout`, for example |
| 35 | + const { options } = await init({ |
| 36 | + authOptions: authOptions, |
| 37 | + action: "signout", |
| 38 | + providerId: "github", |
| 39 | + url: new URL("http://localhost:3000/auth/signout"), |
| 40 | + cookies: {}, |
| 41 | + isPost: true, |
| 42 | + csrfDisabled: true, |
| 43 | + }) |
| 44 | + |
| 45 | + expect(options.url).toBeInstanceOf(URL) |
| 46 | + expect(options.url.toString()).toBe("http://localhost:3000/auth/signout") |
| 47 | + }) |
| 48 | + }) |
| 49 | + describe("sign-in", () => { |
| 50 | + beforeEach(() => { |
| 51 | + vi.resetAllMocks() |
| 52 | + }) |
| 53 | + |
| 54 | + it("should attempt to render signin page", async () => { |
| 55 | + // Generated when visiting `/auth/signin` |
| 56 | + const { options } = await init({ |
| 57 | + authOptions: authOptions, |
| 58 | + action: "signin", |
| 59 | + providerId: "github", |
| 60 | + url: new URL("http://localhost:3000/auth/signin"), |
| 61 | + cookies: {}, |
| 62 | + isPost: true, |
| 63 | + csrfDisabled: true, |
| 64 | + }) |
| 65 | + |
| 66 | + const render = renderPage({ ...options, query: {}, cookies: [] }) |
| 67 | + const signInPage = render.signin() |
| 68 | + |
| 69 | + expect(signInPage.body).toContain(`<title>Sign In</title>`) |
| 70 | + expect(signInPage.body).toContain( |
| 71 | + `action="http://localhost:3000/auth/signin/github"` |
| 72 | + ) |
| 73 | + }) |
| 74 | + }) |
| 75 | +}) |
0 commit comments