Skip to content

Commit

Permalink
fix e2e tests
Browse files Browse the repository at this point in the history
with the new kinde changes the selectors needed to be changed
  • Loading branch information
devksingh4 committed Feb 4, 2025
1 parent aaceebb commit 4889293
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ build
.vscode/settings.json
node_modules/
api/.mise.toml
.env
143 changes: 74 additions & 69 deletions e2e/base.ts
Original file line number Diff line number Diff line change
@@ -1,82 +1,87 @@
import { test as base } from '@playwright/test';
import {sign} from 'jsonwebtoken';
import { sign } from 'jsonwebtoken';
// Extend basic test by providing a "todoPage" fixture.

function generateJWT(email: string, role: string = 'student', env: string = 'dev'): string {
const JWT_SECRET = process.env.RB_JWT_SECRET;
if (!JWT_SECRET) {
console.error("JWT Secret not found in environment variable RB_JWT_SECRET.");
return "";
}
const JWT_SECRET = process.env.RB_JWT_SECRET;
if (!JWT_SECRET) {
console.error("JWT Secret not found in environment variable RB_JWT_SECRET.");
return "";
}

const iat = Math.floor(Date.now() / 1000); // Current time in seconds since the Unix epoch
const exp = iat + (24 * 60 * 60); // Token expiration time (24 hours later)
const iat = Math.floor(Date.now() / 1000); // Current time in seconds since the Unix epoch
const exp = iat + (24 * 60 * 60); // Token expiration time (24 hours later)

const payload = {
iss: 'custom_jwt',
permissions: [`${role}:resume-book-${env}`],
email: email,
exp: exp,
iat: iat,
nbf: iat,
aud: 'https://resumes.aws.qa.acmuiuc.org',
};
const payload = {
iss: 'custom_jwt',
permissions: [`${role}:resume-book-${env}`],
email: email,
exp: exp,
iat: iat,
nbf: iat,
aud: 'https://resumes.aws.qa.acmuiuc.org',
};

return sign(payload, JWT_SECRET, { algorithm: 'HS256' });
return sign(payload, JWT_SECRET, { algorithm: 'HS256' });
}
interface BecomeUserParams {
email?: string
role: string;
email?: string
role: string;
}
async function becomeUser(page, {email, role}: BecomeUserParams) {
if (!email) {
email = process.env.RB_PLAYWRIGHT_USERNAME!;
}
if (email !== process.env.RB_PLAYWRIGHT_USERNAME!) {
const jwt = generateJWT(email, role);
await page.route('**/*', async route => {
if (route.request().url().startsWith('https://resumes.aws.qa.acmuiuc.org/')) {
const token = generateJWT("[email protected]")
const headers = {
...route.request().headers(),
'Authorization': `Bearer ${jwt}`
};

// Continue with modified headers
route.continue({ headers });
} else {
// Continue with the normal routing for other URLs
route.continue();
}
});
}
if (role === 'student') {
await page.goto('https://resumes.qa.acmuiuc.org/login');
await page.getByRole('button', { name: 'Sign in with Illinois NetID' }).click();
await page.getByPlaceholder('[email protected]').click();
await page.getByPlaceholder('[email protected]').fill(process.env.RB_PLAYWRIGHT_USERNAME!);
await page.getByPlaceholder('[email protected]').press('Enter');
await page.getByPlaceholder('Password').click();
await page.getByPlaceholder('Password').fill(process.env.RB_PLAYWRIGHT_PASSWORD!);
await page.getByRole('button', { name: 'Sign in' }).click();
await page.getByRole('button', { name: 'No' }).click();
} else if (role === 'recruiter') {
await page.goto('https://resumes.qa.acmuiuc.org/login');
await page.getByRole('button', { name: 'ACM@UIUC Partner Login' }).click();
await page.getByTestId('auth-email-username-field').click();
await page.getByTestId('auth-email-username-field').fill(process.env.RB_PLAYWRIGHT_USERNAME!);
await page.getByRole('button', { name: 'Continue' }).click();
await page.getByLabel('Password', { exact: true }).fill(process.env.RB_PLAYWRIGHT_PASSWORD!);
await page.getByLabel('Password', { exact: true }).click();
await page.getByRole('button', { name: 'Continue' }).click();
}
async function becomeUser(page, { email, role }: BecomeUserParams) {
if (!email) {
email = process.env.RB_PLAYWRIGHT_USERNAME!;
}
if (email !== process.env.RB_PLAYWRIGHT_USERNAME!) {
const jwt = generateJWT(email, role);
await page.route('**/*', async route => {
if (route.request().url().startsWith('https://resumes.aws.qa.acmuiuc.org/')) {
const token = generateJWT("[email protected]")
const headers = {
...route.request().headers(),
'Authorization': `Bearer ${jwt}`
};

// Continue with modified headers
route.continue({ headers });
} else {
// Continue with the normal routing for other URLs
route.continue();
}
});
}
if (role === 'student') {
await page.goto('https://resumes.qa.acmuiuc.org/login');
await page.getByRole('button', { name: 'Sign in with Illinois NetID' }).click();
await page.getByPlaceholder('[email protected]').click();
await page.getByPlaceholder('[email protected]').fill(process.env.RB_PLAYWRIGHT_USERNAME!);
await page.getByPlaceholder('[email protected]').press('Enter');
await page.getByPlaceholder('Password').click();
await page.getByPlaceholder('Password').fill(process.env.RB_PLAYWRIGHT_PASSWORD!);
await page.getByRole('button', { name: 'Sign in' }).click();
await page.getByRole('button', { name: 'No' }).click();
} else if (role === 'recruiter') {
await page.goto('https://resumes.qa.acmuiuc.org/login');
await page.getByRole('button', { name: 'ACM@UIUC Partner Login' }).click();
await page.waitForTimeout(1000)
await page.locator("#sign_up_sign_in_credentials_p_email_username").click();
await page.locator("#sign_up_sign_in_credentials_p_email_username").fill(process.env.RB_PLAYWRIGHT_USERNAME!);
await page.getByRole('button', { name: 'Continue', exact: true }).click();
await page.getByPlaceholder('[email protected]').click();
await page.getByPlaceholder('[email protected]').fill(process.env.RB_PLAYWRIGHT_USERNAME!);
await page.getByPlaceholder('[email protected]').press('Enter');
await page.getByPlaceholder('Password').click();
await page.getByPlaceholder('Password').fill(process.env.RB_PLAYWRIGHT_PASSWORD!);
await page.getByRole('button', { name: 'Sign in' }).click();
await page.getByRole('button', { name: 'No' }).click();
}
}

export const test = base.extend<{ generateJWT: CallableFunction, becomeUser: (page, params: BecomeUserParams) => Promise<void> }>({
generateJWT: async ({}, use) => {
use(generateJWT)
},
becomeUser: async ({}, use) => {
use(becomeUser)
},
});
generateJWT: async ({ }, use) => {
use(generateJWT)
},
becomeUser: async ({ }, use) => {
use(becomeUser)
},
});
17 changes: 7 additions & 10 deletions e2e/tests/recruiter/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import { test } from '../../base';
import { describe } from 'node:test';

describe("Recruiter login tests", () => {
test('A recruiter can login and view the search screen', async ({ page, becomeUser }) => {
await becomeUser(page, {role: 'recruiter'});
await page.getByRole('link', { name: 'My Account' }).click();
await expect(page.getByRole('button', { name: 'Email resumebook-e2e-testing@' })).toBeVisible();
await expect(page.getByLabel('My Account')).toContainText('RoleRecruiter');
await expect(page.getByLabel('My Account')).toContainText('[email protected]');
await expect(page.getByLabel('My Account')).toContainText('NameResume Book User');
await expect(page.getByRole('heading')).toContainText('Search Resume Book');
});
})
test('A recruiter can login and view the search screen', async ({ page, becomeUser }) => {
await becomeUser(page, { role: 'recruiter' });
await page.getByRole('link', { name: 'My Account' }).click();
await expect(page.getByRole('button', { name: 'Email resumebook-e2e-testing@' })).toBeVisible();
await expect(page.getByRole('heading')).toContainText('Search Resume Book');
});
})

0 comments on commit 4889293

Please sign in to comment.