feat(tools): add fully certified development user (#40181)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
describe('Top contributor in user profile', () => {
|
describe('Top contributor in user profile', () => {
|
||||||
before(() => {
|
before(() => {
|
||||||
cy.clearCookies();
|
cy.clearCookies();
|
||||||
cy.exec('npm run seed:auth-user -- --top-contributor');
|
cy.exec('npm run seed -- --top-contributor');
|
||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
|
@ -43,8 +43,8 @@
|
|||||||
"lint:css": "npm run prettier -- --check",
|
"lint:css": "npm run prettier -- --check",
|
||||||
"prettier": "prettier \"**/*.css\"",
|
"prettier": "prettier \"**/*.css\"",
|
||||||
"postinstall": "npm run bootstrap",
|
"postinstall": "npm run bootstrap",
|
||||||
"seed": "npm-run-all -p seed:*",
|
"seed": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser",
|
||||||
"seed:auth-user": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser",
|
"seed:certified-user": "cross-env DEBUG=fcc:* node ./tools/scripts/seed/seedAuthUser certUser",
|
||||||
"serve:client": "cd ./client && npm run serve",
|
"serve:client": "cd ./client && npm run serve",
|
||||||
"start": "npm-run-all ensure-env -p develop:server serve:client",
|
"start": "npm-run-all ensure-env -p develop:server serve:client",
|
||||||
"test": "npm-run-all -p test:*",
|
"test": "npm-run-all -p test:*",
|
||||||
|
4655
tools/scripts/seed/certifiedUserData.js
Normal file
4655
tools/scripts/seed/certifiedUserData.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,5 @@
|
|||||||
|
const fullyCertifiedUser = require('./certifiedUserData');
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
require('dotenv').config({ path: path.resolve(__dirname, '../../../.env') });
|
require('dotenv').config({ path: path.resolve(__dirname, '../../../.env') });
|
||||||
const MongoClient = require('mongodb').MongoClient;
|
const MongoClient = require('mongodb').MongoClient;
|
||||||
@ -26,28 +28,8 @@ function handleError(err, client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MongoClient.connect(MONGOHQ_URL, { useNewUrlParser: true }, (err, client) => {
|
/* eslint-disable max-len */
|
||||||
handleError(err, client);
|
const authUser = {
|
||||||
|
|
||||||
log('Connected successfully to mongo');
|
|
||||||
|
|
||||||
const db = client.db('freecodecamp');
|
|
||||||
const user = db.collection('user');
|
|
||||||
|
|
||||||
user.deleteMany(
|
|
||||||
{
|
|
||||||
_id: {
|
|
||||||
$in: [
|
|
||||||
ObjectId('5bd30e0f1caf6ac3ddddddb5'),
|
|
||||||
ObjectId('5bd30e0f1caf6ac3ddddddb9')
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
err => {
|
|
||||||
handleError(err, client);
|
|
||||||
|
|
||||||
try {
|
|
||||||
user.insertOne({
|
|
||||||
_id: ObjectId('5bd30e0f1caf6ac3ddddddb5'),
|
_id: ObjectId('5bd30e0f1caf6ac3ddddddb5'),
|
||||||
email: 'foo@bar.com',
|
email: 'foo@bar.com',
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
@ -104,9 +86,8 @@ MongoClient.connect(MONGOHQ_URL, { useNewUrlParser: true }, (err, client) => {
|
|||||||
isDonating: envVariables.includes('--donor'),
|
isDonating: envVariables.includes('--donor'),
|
||||||
emailAuthLinkTTL: null,
|
emailAuthLinkTTL: null,
|
||||||
emailVerifyTTL: null
|
emailVerifyTTL: null
|
||||||
});
|
};
|
||||||
|
const blankUser = {
|
||||||
user.insertOne({
|
|
||||||
_id: ObjectId('5bd30e0f1caf6ac3ddddddb9'),
|
_id: ObjectId('5bd30e0f1caf6ac3ddddddb9'),
|
||||||
email: 'bar@bar.com',
|
email: 'bar@bar.com',
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
@ -161,7 +142,45 @@ MongoClient.connect(MONGOHQ_URL, { useNewUrlParser: true }, (err, client) => {
|
|||||||
isDonating: false,
|
isDonating: false,
|
||||||
emailAuthLinkTTL: null,
|
emailAuthLinkTTL: null,
|
||||||
emailVerifyTTL: null
|
emailVerifyTTL: null
|
||||||
|
};
|
||||||
|
|
||||||
|
MongoClient.connect(MONGOHQ_URL, { useNewUrlParser: true }, (err, client) => {
|
||||||
|
handleError(err, client);
|
||||||
|
|
||||||
|
log('Connected successfully to mongo');
|
||||||
|
|
||||||
|
const db = client.db('freecodecamp');
|
||||||
|
const user = db.collection('user');
|
||||||
|
|
||||||
|
if (process.argv[2] === 'certUser') {
|
||||||
|
user.deleteOne({ _id: ObjectId('5fa2db00a25c1c1fa49ce067') }, err => {
|
||||||
|
handleError(err, client);
|
||||||
|
|
||||||
|
try {
|
||||||
|
user.insertOne(fullyCertifiedUser);
|
||||||
|
} catch (e) {
|
||||||
|
handleError(e, client);
|
||||||
|
} finally {
|
||||||
|
log('local auth user seed complete');
|
||||||
|
client.close();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
user.deleteMany(
|
||||||
|
{
|
||||||
|
_id: {
|
||||||
|
$in: [
|
||||||
|
ObjectId('5bd30e0f1caf6ac3ddddddb5'),
|
||||||
|
ObjectId('5bd30e0f1caf6ac3ddddddb9')
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
err => {
|
||||||
|
handleError(err, client);
|
||||||
|
|
||||||
|
try {
|
||||||
|
user.insertOne(authUser);
|
||||||
|
user.insertOne(blankUser);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
handleError(e, client);
|
handleError(e, client);
|
||||||
} finally {
|
} finally {
|
||||||
@ -170,4 +189,5 @@ MongoClient.connect(MONGOHQ_URL, { useNewUrlParser: true }, (err, client) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user