Merge pull request #4324 from overleaf/jpa-script-create-user

[scripts] refactor create-admin script into generic create-user script

GitOrigin-RevId: a6f5c383888538edd392ffd4da90610c380b83a6
This commit is contained in:
Jakob Ackermann
2021-07-20 11:26:36 +02:00
committed by Copybot
parent fe4c48b7fb
commit f7a4a57487
3 changed files with 78 additions and 76 deletions
@@ -1,5 +1,6 @@
const { execSync } = require('child_process')
const { expect } = require('chai')
const { db } = require('../../../../../app/src/infrastructure/mongodb')
const User = require('../../../../../test/acceptance/src/helpers/User').promises
/**
@@ -18,6 +19,10 @@ function run(cmd) {
}).toString()
}
async function getUser(email) {
return db.users.findOne({ email }, { projection: { _id: 0, isAdmin: 1 } })
}
describe('ServerCEScripts', function () {
describe('check-mongodb', function () {
it('should exit with code 0 on success', function () {
@@ -55,15 +60,25 @@ describe('ServerCEScripts', function () {
})
})
describe('create-admin', function () {
describe('create-user', function () {
it('should exit with code 0 on success', function () {
const out = run('node create-admin --email=foo@bar.com')
expect(out).to.include('/user/password/set?passwordResetToken=')
const out = run('node create-user --email=foo@bar.com')
expect(out).to.include('/user/activate?token=')
})
it('should create a regular user by default', async function () {
run('node create-user --email=foo@bar.com')
expect(await getUser('foo@bar.com')).to.deep.equal({ isAdmin: false })
})
it('should create an admin user with --admin flag', async function () {
run('node create-user --admin --email=foo@bar.com')
expect(await getUser('foo@bar.com')).to.deep.equal({ isAdmin: true })
})
it('should exit with code 1 on missing email', function () {
try {
run('node create-admin')
run('node create-user')
} catch (e) {
expect(e.status).to.equal(1)
return