Skip to content

Commit

Permalink
Fix jest parallel test suites issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Dec 4, 2024
1 parent 8cea4f1 commit 08f5d2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
5 changes: 3 additions & 2 deletions api/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"!**/dist/**",
"!**/__tests__/**"
],
"testTimeout": 120000,
"globalSetup": "./dist/__tests__/globalSetup.js"
"testTimeout": 180000,
"globalSetup": "./dist/__tests__/globalSetup.js",
"maxWorkers": 1
}
22 changes: 8 additions & 14 deletions api/src/common/databaseHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,11 @@ export const initializeLocations = async () => {
const values = await LocationValue.find({ language: { $nin: env.LANGUAGES } })
const valuesIds = values.map((v) => v.id)
for (const val of values) {
const _locations = await Location.find({ values: val.id }).lean()
for (const _loc of _locations) {
const loc = await Location.findById(_loc._id)
if (loc) {
loc.values.splice(loc.values.findIndex((v) => v.equals(val.id)), 1)
await loc.save()
}
await LocationValue.deleteMany({ $and: [{ _id: { $in: _loc.values } }, { _id: { $in: valuesIds } }] })
const _locations = await Location.find({ values: val.id })
for (const _location of _locations) {
_location.values.splice(_location.values.findIndex((v) => v.equals(val.id)), 1)
await _location.save()
await LocationValue.deleteMany({ $and: [{ _id: { $in: _location.values } }, { _id: { $in: valuesIds } }] })
}
}

Expand Down Expand Up @@ -162,13 +159,10 @@ export const initializeCountries = async () => {
const values = await LocationValue.find({ language: { $nin: env.LANGUAGES } })
const valuesIds = values.map((v) => v.id)
for (const val of values) {
const _countries = await Country.find({ values: val.id }).lean()
const _countries = await Country.find({ values: val.id })
for (const _country of _countries) {
const country = await Country.findById(_country._id)
if (country) {
country.values.splice(country.values.findIndex((v) => v.equals(val.id)), 1)
await country.save()
}
_country.values.splice(_country.values.findIndex((v) => v.equals(val.id)), 1)
await _country.save()
await LocationValue.deleteMany({ $and: [{ _id: { $in: _country.values } }, { _id: { $in: valuesIds } }] })
}
}
Expand Down

0 comments on commit 08f5d2c

Please sign in to comment.