Skip to content

Commit

Permalink
test: seed the ms username to avoid mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
ojeytonwilliams committed Apr 23, 2024
1 parent e399123 commit 6f9bbc3
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions e2e/link-ms-user.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { execSync } from 'child_process';

import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';

Expand Down Expand Up @@ -38,6 +40,9 @@ test.describe('Link MS user component (signed-out user)', () => {
});

test.describe('Link MS user component (signed-in user)', () => {
test.afterEach(() => {
execSync('node ./tools/scripts/seed/seed-ms-username');
});
test.use({ storageState: 'playwright/.auth/certified-user.json' });

test("should recognize the user's MS account", async ({ page }) => {
Expand All @@ -48,23 +53,14 @@ test.describe('Link MS user component (signed-in user)', () => {
})
).toBeVisible();

await expect(
page.getByText(
'The Microsoft account with username "certifieduser" is currently linked to your freeCodeCamp account. If this is not your Microsoft username, remove the link.'
)
).toBeVisible();
await expect(page.locator('main')).toHaveText(
/The Microsoft account with username "certifieduser" is currently linked to your freeCodeCamp account. If this is not your Microsoft username, remove the link./
);
});

test('should allow the user to unlink their MS account and display a form for re-link', async ({
page
}) => {
// Intercept the endpoint to prevent `msUsername` from being deleted
// as the deletion will cause subsequent tests to fail
await page.route('*/**/user/ms-username', async route => {
const json = { msUsername: null };
await route.fulfill({ json });
});

const unlinkButton = page.getByRole('button', {
name: translations.buttons['unlink-account']
});
Expand Down

0 comments on commit 6f9bbc3

Please sign in to comment.