Skip to content

Commit

Permalink
Merge branch 'main' into 11384-no-unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
esizer committed Oct 2, 2024
2 parents 55ebcc5 + c9416f3 commit c8e9700
Show file tree
Hide file tree
Showing 215 changed files with 695 additions and 653 deletions.
18 changes: 10 additions & 8 deletions apps/playwright/tests/admin/pool-candidate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test.describe("Pool candidates", () => {
test.beforeAll(async () => {
const adminCtx = await graphql.newContext();

const technicalSkill = await getSkills(adminCtx).then((skills) => {
const technicalSkill = await getSkills(adminCtx, {}).then((skills) => {
return skills.find(
(skill) => skill.category.value === SkillCategory.Technical,
);
Expand Down Expand Up @@ -59,8 +59,8 @@ test.describe("Pool candidates", () => {
skills: {
sync: [
{
details: `Test Skill ${technicalSkill.name.en}`,
id: technicalSkill.id,
details: `Test Skill ${technicalSkill?.name.en}`,
id: technicalSkill?.id ?? "",
},
],
},
Expand All @@ -73,18 +73,20 @@ test.describe("Pool candidates", () => {
});

const createdPool = await createAndPublishPool(adminCtx, {
userId: createdUser.id,
skillId: technicalSkill.id,
userId: createdUser?.id ?? "",
skillId: technicalSkill?.id ?? "",
name: LOCALIZED_STRING,
});

const applicantCtx = await graphql.newContext(createdUser.authInfo.sub);
const applicant = await me(applicantCtx);
const applicantCtx = await graphql.newContext(
createdUser?.authInfo?.sub ?? "[email protected]",
);
const applicant = await me(applicantCtx, {});

const application = await createAndSubmitApplication(applicantCtx, {
userId: applicant.id,
poolId: createdPool.id,
experienceId: applicant.experiences[0].id,
experienceId: applicant?.experiences?.[0]?.id ?? "",
signature: `${applicant.firstName} signature`,
});

Expand Down
4 changes: 2 additions & 2 deletions apps/playwright/tests/admin/process-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ test.describe("Process actions", () => {
test("Update pool", async ({ adminPage }) => {
const adminCtx = await graphql.newContext();

const user = await me(adminCtx);
const user = await me(adminCtx, {});
const poolName = {
en: "Update pool test (EN)",
fr: "Update pool test (FR)",
Expand Down Expand Up @@ -259,7 +259,7 @@ test.describe("Process actions", () => {
test("Delete pool", async ({ adminPage }) => {
const adminCtx = await graphql.newContext();

const user = await me(adminCtx);
const user = await me(adminCtx, {});

const createdPool = await createPool(adminCtx, {
userId: user.id,
Expand Down
11 changes: 8 additions & 3 deletions apps/playwright/tests/admin/process-permissions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,23 @@ test.describe("Process permissions", () => {
],
});

const team = await getDCM(adminCtx);
const team = await getDCM(adminCtx, {});

const associatedPoolManager = await createUserWithRoles(adminCtx, {
user: {
email: associatedPoolManagerEmail,
sub: associatedSub,
},
roles: ["guest", "base_user", "applicant", ["pool_operator", team.id]],
roles: [
"guest",
"base_user",
"applicant",
["pool_operator", team?.id ?? ""],
],
});

const createdPool = await createPool(adminCtx, {
userId: associatedPoolManager.id,
userId: associatedPoolManager?.id ?? "",
});

await updatePool(adminCtx, {
Expand Down
24 changes: 12 additions & 12 deletions apps/playwright/tests/admin/user-info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test.describe("User information", () => {
let uniqueTestId: string;
let user: User;
let sub: string;
let skill: Skill;
let skill: Skill | undefined;

const loginAndVisitUser = async (
appPage: AppPage,
Expand All @@ -36,7 +36,7 @@ test.describe("User information", () => {
}),
).toBeVisible();
await expect(
page.getByText(new RegExp(user.firstName, "i")).first(),
page.getByText(new RegExp(user?.firstName ?? "", "i")).first(),
).toBeVisible();
};

Expand All @@ -53,7 +53,7 @@ test.describe("User information", () => {

adminCtx = await graphql.newContext();

const technicalSkill = await getSkills(adminCtx).then((skills) => {
const technicalSkill = await getSkills(adminCtx, {}).then((skills) => {
return skills.find((s) => s.category.value === SkillCategory.Technical);
});

Expand All @@ -70,8 +70,8 @@ test.describe("User information", () => {
skills: {
sync: [
{
details: `Test Skill ${technicalSkill.name.en}`,
id: technicalSkill.id,
details: `Test Skill ${technicalSkill?.name.en}`,
id: technicalSkill?.id ?? "",
},
],
},
Expand All @@ -85,12 +85,12 @@ test.describe("User information", () => {
});

skill = technicalSkill;
user = createdUser;
user = createdUser ?? { id: "" };
});

test("Applicant cannot access", async ({ appPage }) => {
await loginBySub(appPage.page, "[email protected]", false);
await appPage.page.goto(`/en/admin/users/${user.id}`);
await appPage.page.goto(`/en/admin/users/${user?.id}`);
await appPage.waitForGraphqlResponse("authorizationQuery");
await expect(
appPage.page.getByRole("heading", {
Expand All @@ -104,24 +104,24 @@ test.describe("User information", () => {
await loginAndVisitUser(appPage, "[email protected]", user);
await assertError(appPage.page);

const adminUser = await me(adminCtx);
const adminUser = await me(adminCtx, {});

const dcmPool = await createAndPublishPool(adminCtx, {
userId: adminUser.id,
name: {
en: `Playwright DCM Pool ${uniqueTestId} (EN)`,
fr: `Playwright DCM Pool ${uniqueTestId} (FR)`,
},
skillId: skill.id,
skillId: skill?.id ?? "",
});

const applicantCtx = await graphql.newContext(sub);
const applicant = await me(applicantCtx);
const applicant = await me(applicantCtx, {});
await createAndSubmitApplication(applicantCtx, {
userId: applicant.id,
poolId: dcmPool.id,
experienceId: applicant.experiences[0].id,
signature: `${user.firstName} signature`,
experienceId: applicant?.experiences?.[0]?.id ?? "",
signature: `${user?.firstName} signature`,
});

// Pool operator can view now that user has application in their pool
Expand Down
2 changes: 1 addition & 1 deletion apps/playwright/tests/applicant/application-iap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test.describe("IAP Application", () => {
});

const createdPool = await createAndPublishPool(adminCtx, {
userId: createdUser.id,
userId: createdUser?.id ?? "",
input: {
publishingGroup: PublishingGroup.Iap,
generalQuestions: {
Expand Down
18 changes: 7 additions & 11 deletions apps/playwright/tests/applicant/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test.describe("Application", () => {
en: `${poolName} (EN)`,
fr: `${poolName} (FR)`,
},
userId: createdUser.id,
userId: createdUser?.id ?? "",
input: {
generalQuestions: {
create: [
Expand Down Expand Up @@ -243,8 +243,8 @@ test.describe("Application", () => {

test("Can view from dashboard", async ({ page }) => {
const applicantCtx = await graphql.newContext(sub);
const applicant = await me(applicantCtx);
const technicalSkill = await getSkills(applicantCtx).then((skills) => {
const applicant = await me(applicantCtx, {});
const technicalSkill = await getSkills(applicantCtx, {}).then((skills) => {
return skills.find((s) => s.category.value === SkillCategory.Technical);
});

Expand All @@ -259,8 +259,8 @@ test.describe("Application", () => {
skills: {
sync: [
{
details: `Test Skill ${technicalSkill.name.en}`,
id: technicalSkill.id,
details: `Test Skill ${technicalSkill?.name.en}`,
id: technicalSkill?.id ?? "",
},
],
},
Expand All @@ -271,11 +271,11 @@ test.describe("Application", () => {
},
},
});
const applicantWithExperiences = await me(applicantCtx);
const applicantWithExperiences = await me(applicantCtx, {});
await createApplication(applicantCtx, {
userId: applicantWithExperiences.id,
poolId: pool.id,
experienceId: applicantWithExperiences.experiences[0].id,
experienceId: applicantWithExperiences?.experiences?.[0]?.id ?? "",
});

await loginBySub(page, sub, false);
Expand All @@ -286,9 +286,5 @@ test.describe("Application", () => {
level: 2,
}),
).toBeVisible();

await expect(
page.getByRole("link", { name: /continue draft/i }),
).toBeVisible();
});
});
24 changes: 13 additions & 11 deletions apps/playwright/tests/login-logout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ test.describe("Login and logout", () => {

// complete login process
const request = await requestPromise;
const location = await request
.response()
.then((res) => res.headerValue("location"));
const location = String(
await request
.response()
.then((res) => res?.headerValue("location") ?? ""),
);
const url = new URL(location);
const searchParamAccessToken = url.searchParams.get("access_token");

Expand Down Expand Up @@ -113,7 +115,7 @@ test.describe("Login and logout", () => {

// time travel to when the tokens expire before trying to navigate
const tokenSet1 = await getAuthTokens(page);
await clockHelper.jumpTo(jumpPastExpiryDate(tokenSet1.accessToken));
await clockHelper.jumpTo(jumpPastExpiryDate(tokenSet1?.accessToken ?? ""));

const request = await requestPromise;
await page.goto("/en/applicant");
Expand Down Expand Up @@ -160,7 +162,7 @@ test.describe("Login and logout", () => {
}
return false;
})
.then(async (request) => {
.then((request) => {
// make sure it uses the access token
expect(request.headers().authorization).toEqual(
`Bearer ${tokenSet1.accessToken}`,
Expand All @@ -180,7 +182,7 @@ test.describe("Login and logout", () => {
// get auth tokens set 1
const tokenSet1 = await getAuthTokens(page);
// time travel to when the tokens from token set 1 expire before trying to navigate
await clockHelper.jumpTo(jumpPastExpiryDate(tokenSet1.accessToken));
await clockHelper.jumpTo(jumpPastExpiryDate(tokenSet1?.accessToken ?? ""));

const request = await requestPromise;
// navigate to a page
Expand All @@ -204,7 +206,7 @@ test.describe("Login and logout", () => {
}
return false;
})
.then(async (req) => {
.then((req) => {
// make sure it uses the second access token
expect(req.headers().authorization).toEqual(
`Bearer ${tokenSet2.accessToken}`,
Expand All @@ -214,7 +216,7 @@ test.describe("Login and logout", () => {
// reset clock
await clockHelper.restore();
// time travel to when the tokens from token set 2 expire before trying to navigate
await clockHelper.jumpTo(jumpPastExpiryDate(tokenSet2.accessToken));
await clockHelper.jumpTo(jumpPastExpiryDate(tokenSet2?.accessToken ?? ""));

const request2 = await requestPromise;
// navigate to a page
Expand All @@ -238,7 +240,7 @@ test.describe("Login and logout", () => {
}
return false;
})
.then(async (req) => {
.then((req) => {
// make sure it uses the third access token
expect(req.headers().authorization).toEqual(
`Bearer ${tokenSet3.accessToken}`,
Expand All @@ -248,7 +250,7 @@ test.describe("Login and logout", () => {
// reset clock
await clockHelper.restore();
// time travel to when the tokens from token set 3 expire before trying to navigate
await clockHelper.jumpTo(jumpPastExpiryDate(tokenSet3.accessToken));
await clockHelper.jumpTo(jumpPastExpiryDate(tokenSet3?.accessToken ?? ""));

const request3 = await requestPromise;
// navigate to a page
Expand All @@ -275,7 +277,7 @@ test.describe("Login and logout", () => {
await page.goto("/en/logged-out");
await page.getByRole("button", { name: "Sign out" }).click();

await requestPromise.then(async (req) => {
await requestPromise.then((req) => {
const url = new URL(req.url());
const searchParamPostLogoutRedirectUri = url.searchParams.get(
"post_logout_redirect_uri",
Expand Down
10 changes: 6 additions & 4 deletions apps/playwright/tests/open-graph.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { test, expect } from "@playwright/test";
test.describe("Open Graph", () => {
test("should specify an image", async ({ page }) => {
await page.goto("/en");
const locator = await page
.locator('head meta[property="og:image"]')
.getAttribute("content");
const locator = String(
await page
.locator('head meta[property="og:image"]')
.getAttribute("content"),
);
await page.goto(locator).then((response) => {
expect(response.status()).toEqual(200);
expect(response?.status()).toEqual(200);
});
});
});
Loading

0 comments on commit c8e9700

Please sign in to comment.