-
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.
- Loading branch information
Showing
3 changed files
with
139 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { expect, test } from "@playwright/test"; | ||
import type { Context } from "../helpers/context"; | ||
import { | ||
contextDefaults, | ||
setUpTestContext, | ||
tearDownTestContext, | ||
} from "../helpers/context"; | ||
import { createAuthenticatedSession } from "../helpers/globalHelpers"; | ||
|
||
test.describe("Login", () => { | ||
let context: Context = { | ||
...contextDefaults, | ||
}; | ||
|
||
test.beforeAll(async () => { | ||
try { | ||
context = await setUpTestContext(context); | ||
} catch (error) { | ||
// ensure proper teardown if setup fails | ||
await tearDownTestContext(context); | ||
throw error; | ||
} | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await tearDownTestContext(context); | ||
}); | ||
|
||
test("setting a cookie bypasses login", async ({ browser }) => { | ||
const page = await createAuthenticatedSession({ | ||
browser, | ||
userId: context.user!.id!, | ||
}); | ||
|
||
await page.goto("/"); | ||
await page.waitForResponse((response) => { | ||
return response.url().includes("/graphql"); | ||
}); | ||
|
||
const team = page.locator("h3", { hasText: context.team.name }); | ||
await expect(team).toBeVisible(); | ||
}); | ||
|
||
test("shows error toast when there is a network error and removes it when a retry is successful", async ({ | ||
browser, | ||
}) => { | ||
const page = await createAuthenticatedSession({ | ||
browser, | ||
userId: context.user!.id!, | ||
}); | ||
await page.goto("/"); | ||
|
||
const teamLink = page.locator("h3").filter({ hasText: context.team.name }); | ||
await teamLink.waitFor(); // wait for this to be visible | ||
|
||
// drop graphql requests | ||
await page.route("**/graphql", (route) => { | ||
route.abort("connectionfailed"); | ||
}); | ||
|
||
await teamLink.click(); | ||
const toastText = "Network error, attempting to reconnect…"; | ||
await expect(page.getByText(toastText)).toBeVisible(); | ||
|
||
// resume graphql requests | ||
await page.route("**/graphql", (route) => { | ||
route.continue(); | ||
}); | ||
await expect( | ||
page.locator("h1").filter({ hasText: "Services" }), | ||
).toBeVisible(); | ||
await expect(page.getByText(toastText)).toBeHidden(); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -46,6 +46,28 @@ export const contextDefaults: Context = { | |
}, | ||
}; | ||
|
||
export const demoContext: Context = { | ||
user: { | ||
firstName: "Demo", | ||
lastName: "demo", | ||
email: "[email protected]", | ||
isPlatformAdmin: false, | ||
}, | ||
team: { | ||
name: "E2E Test Team", | ||
slug: "E2E", | ||
theme: { | ||
logo: "https://raw.githubusercontent.com/theopensystemslab/planx-team-logos/main/planx-testing.svg", | ||
primaryColour: "#444444", | ||
}, | ||
settings: { | ||
homepage: "planx.uk", | ||
submissionEmail: "[email protected]", | ||
}, | ||
}, | ||
}; | ||
|
||
|
||
export async function setUpTestContext( | ||
initialContext: Context, | ||
): Promise<Context> { | ||
|
@@ -121,6 +143,21 @@ export function generateAuthenticationToken(userId: string) { | |
); | ||
} | ||
|
||
export function generateAuthenticationDemoToken(userId: string) { | ||
assert(process.env.JWT_SECRET); | ||
return sign( | ||
{ | ||
sub: `${userId}`, | ||
"https://hasura.io/jwt/claims": { | ||
"x-hasura-allowed-roles": ["public","demoUser"], | ||
"x-hasura-default-role": "demoUser", | ||
"x-hasura-user-id": `${userId}`, | ||
}, | ||
}, | ||
process.env.JWT_SECRET, | ||
); | ||
} | ||
|
||
export function getCoreDomainClient(): CoreDomainClient { | ||
assert(process.env.HASURA_GRAPHQL_URL); | ||
assert(process.env.HASURA_GRAPHQL_ADMIN_SECRET); | ||
|
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