Skip to content

Commit

Permalink
[Fix] Nullish coalescing eslint errors (#11651)
Browse files Browse the repository at this point in the history
* turn rule back on

* fix theme provider errors

* fix fake data errors

* fix date-helper errors

* fix theme decorator errors

* add strict null checks in playwright

* fix form errors

* fix i18n errors

* fix ui errors

* fix web errors

* fix strict null types in playwright

* fix experience mutations type

* fix remaining errors

* fix auth token return

* fix login-logout test

* fix application spec

* fix theme decorator

* Apply suggestions from code review

Co-authored-by: Peter Giles <[email protected]>

* fix localized names null fallbacks

* ignore boolean primitives

* fix theme decorator

---------

Co-authored-by: Peter Giles <[email protected]>
  • Loading branch information
esizer and petertgiles authored Oct 2, 2024
1 parent 0fa30b3 commit c9416f3
Show file tree
Hide file tree
Showing 133 changed files with 341 additions and 313 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();
});
});
16 changes: 9 additions & 7 deletions apps/playwright/tests/login-logout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,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 @@ -104,7 +106,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 @@ -171,7 +173,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 Down Expand Up @@ -205,7 +207,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 Down Expand Up @@ -239,7 +241,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 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);
});
});
});
22 changes: 11 additions & 11 deletions apps/playwright/tests/search-workflows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test.describe("Talent search", () => {
const sub = `playwright.sub.${uniqueTestId}`;
const poolName = `Search pool ${uniqueTestId}`;
let classification: Classification;
let skill: Skill;
let skill: Skill | undefined;

const expectNoCandidate = async (page: Page) => {
await expect(
Expand All @@ -38,7 +38,7 @@ test.describe("Talent search", () => {
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((s) => s.category.value === SkillCategory.Technical);
});
skill = technicalSkill;
Expand All @@ -62,8 +62,8 @@ test.describe("Talent search", () => {
skills: {
sync: [
{
details: `Test Skill ${technicalSkill.name.en}`,
id: technicalSkill.id,
details: `Test Skill ${technicalSkill?.name.en}`,
id: technicalSkill?.id ?? "",
},
],
},
Expand All @@ -76,14 +76,14 @@ test.describe("Talent search", () => {
roles: ["guest", "base_user", "applicant"],
});

const classifications = await getClassifications(adminCtx);
const classifications = await getClassifications(adminCtx, {});
classification = classifications[0];

const adminUser = await me(adminCtx);
const adminUser = await me(adminCtx, {});
// Accepted pool
const createdPool = await createAndPublishPool(adminCtx, {
userId: adminUser.id,
skillId: technicalSkill.id,
skillId: technicalSkill?.id,
classificationId: classification.id,
name: {
en: poolName,
Expand All @@ -92,12 +92,12 @@ test.describe("Talent search", () => {
});

const applicantCtx = await graphql.newContext(sub);
const applicant = await me(applicantCtx);
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}`,
});

Expand Down Expand Up @@ -157,7 +157,7 @@ test.describe("Talent search", () => {
name: /^skill$/i,
});

await skillFilter.fill(`${skill.name.en}`);
await skillFilter.fill(`${skill?.name.en}`);
await skillFilter.press("ArrowDown");
await skillFilter.press("Enter");

Expand Down Expand Up @@ -225,7 +225,7 @@ test.describe("Talent search", () => {
).toBeVisible();

await expect(
appPage.page.getByText(new RegExp(skill.name.en)),
appPage.page.getByText(new RegExp(skill?.name.en ?? "")),
).toBeVisible();

await expect(appPage.page.getByText(/required diploma/i)).toBeVisible();
Expand Down
1 change: 1 addition & 0 deletions apps/playwright/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"resolveJsonModule": true,
"moduleResolution": "Bundler",
"esModuleInterop": true,
"strictNullChecks": true,
"paths": {
"~/*": ["./*"]
}
Expand Down
Loading

0 comments on commit c9416f3

Please sign in to comment.