Skip to content

Commit

Permalink
feat(tools): allow seed script to set user flags (freeCodeCamp#55534)
Browse files Browse the repository at this point in the history
  • Loading branch information
ojeytonwilliams authored Jul 21, 2024
1 parent 13828c6 commit d626997
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 48 deletions.
2 changes: 1 addition & 1 deletion e2e/academic-honesty.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ test.describe('When the user has not accepted the Academic Honesty Policy', () =
});

test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});
});
2 changes: 1 addition & 1 deletion e2e/cert-username-case-navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ test.describe('Public profile certifications', () => {
});

test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});
});
2 changes: 1 addition & 1 deletion e2e/challenge-reset-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ test.describe('Signed in user', () => {
});

test.afterEach(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});

test('User can reset on a multi-file project after reloading and saving', async ({
Expand Down
4 changes: 2 additions & 2 deletions e2e/codeally.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test.describe('Before completing the project', () => {
test.use({ storageState: 'playwright/.auth/development-user.json' });

test.beforeEach(() => {
execSync('node ./tools/scripts/seed/seed-demo-user --donor');
execSync('node ./tools/scripts/seed/seed-demo-user --set-true isDonating');
});

test('should not allow you to submit a URL', async ({ page }) => {
Expand All @@ -26,7 +26,7 @@ test.describe('After completing the project', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });

test.beforeAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});

test('should allow you to submit a URL', async ({ page }) => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/delete-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test.beforeEach(async ({ page }) => {
test.afterAll(
async () =>
await Promise.all([
await execP('node ./tools/scripts/seed/seed-demo-user certified-user'),
await execP('node ./tools/scripts/seed/seed-demo-user --certified-user'),
await execP('node ./tools/scripts/seed/seed-surveys'),
await execP('node ./tools/scripts/seed/seed-ms-username')
])
Expand Down
4 changes: 2 additions & 2 deletions e2e/donate-page-donor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ test.describe('Donate page', () => {
test.use({ storageState: 'playwright/.auth/development-user.json' });

test.beforeEach(async ({ page }) => {
execSync('node ./tools/scripts/seed/seed-demo-user --donor');
execSync('node ./tools/scripts/seed/seed-demo-user --set-true isDonating');
await page.goto('/donate');
});

test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});

test('should render the donate page correctly', async ({ page }) => {
Expand Down
8 changes: 5 additions & 3 deletions e2e/donation-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ test.describe('Donation modal appearance logic - New user', () => {
});

test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});

test('should not appear if the user has less than 10 completed challenges in total and has just completed 3 challenges', async ({
Expand Down Expand Up @@ -373,11 +373,13 @@ test.describe('Donation modal appearance logic - Donor user', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });

test.beforeAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user --donor');
execSync(
'node ./tools/scripts/seed/seed-demo-user --certified-user --set-true isDonating'
);
});

test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});

test('should not appear', async ({
Expand Down
2 changes: 1 addition & 1 deletion e2e/email-settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const newEmail = '[email protected]';
test.use({ storageState: 'playwright/.auth/certified-user.json' });

test.beforeEach(async ({ page }) => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
await page.goto('/settings');
});

Expand Down
2 changes: 1 addition & 1 deletion e2e/exam-survey.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const url =
test.describe('Exam Survey', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });
test.beforeAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
execSync('node tools/scripts/seed/seed-surveys.js delete-only');
});

Expand Down
2 changes: 1 addition & 1 deletion e2e/failed-updates.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test.beforeAll(() => {
});

test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});

test.describe('failed update flushing', () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ setup.describe('developmentuser', () => {
});

setup.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});

setup('can sign in', async ({ request }) => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test.describe('Header', () => {
});

test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});

test('Has link for skip content', async ({ page }) => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/multifile-cert-projects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { clearEditor, focusEditor } from './utils/editor';
test.use({ storageState: 'playwright/.auth/certified-user.json' });
test.describe('multifileCertProjects', () => {
test.beforeEach(async ({ page }) => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
await page.goto(
'learn/2022/responsive-web-design/build-a-tribute-page-project/build-a-tribute-page'
);
Expand Down
2 changes: 1 addition & 1 deletion e2e/portfolio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test.beforeAll(() => {
});

test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});

test.describe('Add Portfolio Item', () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/progress-reset-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test.beforeEach(async ({ page }) => {
});

test.afterEach(async () => {
await execP('node ./tools/scripts/seed/seed-demo-user certified-user');
await execP('node ./tools/scripts/seed/seed-demo-user --certified-user');
});

test.describe('Progress reset modal', () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/projects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test.beforeAll(() => {
});

test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});

test.describe('Projects', () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/quincy-email-sign-up.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ test.describe('Email sign-up page when user is signed in', () => {
// terms, otherwise the user will be redirected away from the email sign-up
// page.
execSync(
'node ./tools/scripts/seed/seed-demo-user certified-user --unset-privacy-terms'
'node ./tools/scripts/seed/seed-demo-user --certified-user --set-false acceptedPrivacyTerms'
);

await page.goto('/email-sign-up');
Expand Down
2 changes: 1 addition & 1 deletion e2e/show-cert-from-superblock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test.describe('When the user HAS NOT claimed their cert', () => {
});

test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});
});

Expand Down
2 changes: 1 addition & 1 deletion e2e/user-token.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test.beforeEach(() => {
});

test.afterAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user certified-user');
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});

test.describe('Initially', () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"playwright:install-build-tools": "npx playwright install --with-deps",
"rename-challenges": "ts-node tools/challenge-helper-scripts/rename-challenge-files.ts",
"seed": "pnpm seed:surveys && pnpm seed:exams && DEBUG=fcc:* node ./tools/scripts/seed/seed-demo-user",
"seed:certified-user": "pnpm seed:surveys && pnpm seed:exams && pnpm seed:ms-username && DEBUG=fcc:* node ./tools/scripts/seed/seed-demo-user certified-user",
"seed:certified-user": "pnpm seed:surveys && pnpm seed:exams && pnpm seed:ms-username && DEBUG=fcc:* node ./tools/scripts/seed/seed-demo-user --certified-user",
"seed:exams": "DEBUG=fcc:* node tools/scripts/seed-exams/create-exams",
"seed:surveys": "DEBUG=fcc:* node ./tools/scripts/seed/seed-surveys",
"seed:ms-username": "DEBUG=fcc:* node ./tools/scripts/seed/seed-ms-username",
Expand Down
42 changes: 18 additions & 24 deletions tools/scripts/seed/seed-demo-user.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { parseArgs } = require('node:util');

const path = require('path');
const debug = require('debug');
const { MongoClient } = require('mongodb');
Expand All @@ -11,23 +13,15 @@ const {
userIds
} = require('./user-data');

const args = process.argv.slice(2);
const options = {
'set-true': { type: 'string', multiple: true },
'top-contributor': { type: 'boolean' },
'set-false': { type: 'string', multiple: true },
'seed-trophy-challenges': { type: 'boolean' },
'certified-user': { type: 'boolean' }
};

const allowedArgs = [
'--donor',
'--top-contributor',
'--unset-privacy-terms',
'--seed-trophy-challenges',
'certified-user'
];

// Check for invalid arguments
args.forEach(arg => {
if (!allowedArgs.includes(arg))
throw new Error(
`Invalid argument ${arg}. Allowed arguments are ${allowedArgs.join(', ')}`
);
});
const { values: argValues } = parseArgs({ options });

const log = debug('fcc:tools:seedLocalAuthUser');
const { MONGOHQ_URL } = process.env;
Expand Down Expand Up @@ -87,16 +81,16 @@ const trophyChallenges = [
];

[demoUser, blankUser, fullyCertifiedUser].forEach(user => {
if (args.includes('--donor')) {
user.isDonating = true;
}
if (args.includes('--top-contributor')) {
if (argValues['top-contributor']) {
user.yearsTopContributor = ['2017', '2018', '2019'];
}
if (args.includes('--unset-privacy-terms')) {
user.acceptedPrivacyTerms = false;
for (const key of argValues['set-false'] || []) {
user[key] = false;
}
for (const key of argValues['set-true'] || []) {
user[key] = true;
}
if (args.includes('--seed-trophy-challenges')) {
if (argValues['--seed-trophy-challenges']) {
user.completedChallenges = trophyChallenges;
}
});
Expand Down Expand Up @@ -128,7 +122,7 @@ const run = async () => {

await dropUserTokens();
await dropUsers();
if (args.includes('certified-user')) {
if (argValues['certified-user']) {
await user.insertOne(fullyCertifiedUser);
await user.insertOne(blankUser);
await user.insertOne(publicUser);
Expand Down

0 comments on commit d626997

Please sign in to comment.