Skip to content

Commit

Permalink
Update testHelper.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Nov 18, 2024
1 parent 21efaa9 commit 4c9247d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dev": "nodemon",
"build": "rimraf dist && cross-env NODE_OPTIONS=--max-old-space-size=1024 tsc --build --verbose && babel dist -d dist",
"start": "npm run build && node dist/src",
"test": "rimraf coverage && npm run build && cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --coverage --no-cache",
"test": "rimraf coverage && npm run build && cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --coverage --no-cache --runInBand",
"lint": "eslint --ext .ts .",
"ncu": "ncu -u -x typescript,eslint,@types/express",
"db:script": "npm run build && node dist/scripts/db.js"
Expand Down
28 changes: 10 additions & 18 deletions api/tests/testHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,17 @@ export const initialize = async () => {

// env admin
if (env.ADMIN_EMAIL) {
let adminFromEnv = await User.findOne({ email: env.ADMIN_EMAIL, type: bookcarsTypes.UserType.Admin })
const adminFromEnv = await User.findOne({ email: env.ADMIN_EMAIL })
if (!adminFromEnv) {
//
// This check is necessary to avoid getting an error creating the same env admin multiple times when
// test suites are run in parallel.
//
await delay(1000)
adminFromEnv = await User.findOne({ email: env.ADMIN_EMAIL })
if (!adminFromEnv) {
const _admin = new User({
fullName: 'admin',
email: env.ADMIN_EMAIL,
language: LANGUAGE,
password: passwordHash,
type: bookcarsTypes.UserType.Admin,
})
await _admin.save()
expect(_admin.id).toBeTruthy()
}
const _admin = new User({
fullName: 'admin',
email: env.ADMIN_EMAIL,
language: LANGUAGE,
password: passwordHash,
type: bookcarsTypes.UserType.Admin,
})
await _admin.save()
expect(_admin.id).toBeTruthy()
}
}

Expand Down

0 comments on commit 4c9247d

Please sign in to comment.