(mode?: string)
| 27 | } |
| 28 | |
| 29 | const runTests = (mode?: string) => { |
| 30 | describe("Tests", () => { |
| 31 | describe("unauthenticated", () => { |
| 32 | it( |
| 33 | "should render error for protected query - client", |
| 34 | async () => { |
| 35 | await waitPort({port: appPort}) |
| 36 | const browser = await webdriver(appPort, "/authenticated-client") |
| 37 | let errorMsg = await browser.elementById(`error`).text() |
| 38 | expect(errorMsg).toMatch(/Error: You are not authenticated/) |
| 39 | if (browser) await browser.close() |
| 40 | }, |
| 41 | 5000 * 60 * 2, |
| 42 | ) |
| 43 | |
| 44 | it( |
| 45 | "should render error for protected query - server component", |
| 46 | async () => { |
| 47 | await waitPort({port: appPort}) |
| 48 | const browser = await webdriver(appPort, "/authenticated-server") |
| 49 | let errorMsg = await browser.elementById(`error`).text() |
| 50 | expect(errorMsg).toMatch(/Error: You are not authenticated/) |
| 51 | if (browser) await browser.close() |
| 52 | }, |
| 53 | 5000 * 60 * 2, |
| 54 | ) |
| 55 | |
| 56 | it( |
| 57 | "should render result for open query", |
| 58 | async () => { |
| 59 | const res = await fetch(`http://localhost:${appPort}/api/noauth`, { |
| 60 | method: "POST", |
| 61 | headers: {"Content-Type": "application/json; charset=utf-8"}, |
| 62 | }) |
| 63 | expect(res.status).toBe(200) |
| 64 | }, |
| 65 | 5000 * 60 * 2, |
| 66 | ) |
| 67 | |
| 68 | it("sets correct cookie", async () => { |
| 69 | const res = await fetch(`http://localhost:${appPort}/api/noauth`, { |
| 70 | method: "POST", |
| 71 | headers: {"Content-Type": "application/json; charset=utf-8"}, |
| 72 | }) |
| 73 | const cookieHeader = res.headers.get("Set-Cookie") |
| 74 | const cookie = (name) => readCookie(cookieHeader, name) |
| 75 | |
| 76 | expect(res.status).toBe(200) |
| 77 | expect(res.headers.get(HEADER_CSRF)).not.toBe(undefined) |
| 78 | expect(cookie(COOKIE_ANONYMOUS_SESSION_TOKEN)).not.toBeUndefined() |
| 79 | expect(cookie(COOKIE_SESSION_TOKEN)).toBe("") |
| 80 | expect(cookie(COOKIE_REFRESH_TOKEN)).toBeUndefined() |
| 81 | |
| 82 | expect(res.headers.get(HEADER_PUBLIC_DATA_TOKEN)).toBe("updated") |
| 83 | expect(cookie(COOKIE_PUBLIC_DATA_TOKEN)).not.toBe(undefined) |
| 84 | |
| 85 | const publicDataStr = fromBase64(cookie(COOKIE_PUBLIC_DATA_TOKEN)) |
| 86 | const publicData = JSON.parse(publicDataStr) |
no test coverage detected