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 837d577 commit 048455e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
3 changes: 2 additions & 1 deletion api/jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
"!**/__tests__/**"
],
"testTimeout": 180000,
"globalSetup": "./dist/__tests__/globalSetup.js"
"globalSetup": "./dist/__tests__/globalSetup.js",
"maxWorkers": 1
}
31 changes: 11 additions & 20 deletions api/src/common/databaseHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,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 location = await Location.findById(_loc._id)
if (location) {
location.values.splice(location.values.findIndex((v) => v.equals(val.id)), 1)
await location.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 @@ -165,13 +162,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 Expand Up @@ -226,13 +220,10 @@ export const initializeParkingSpots = async () => {
const values = await LocationValue.find({ language: { $nin: env.LANGUAGES } })
const valuesIds = values.map((v) => v.id)
for (const val of values) {
const _parkingSpots = await ParkingSpot.find({ values: val.id }).lean()
const _parkingSpots = await ParkingSpot.find({ values: val.id })
for (const _parkingSpot of _parkingSpots) {
const parkingSpot = await ParkingSpot.findById(_parkingSpot._id)
if (parkingSpot) {
parkingSpot.values.splice(_parkingSpot.values.findIndex((v) => v.equals(val.id)), 1)
await parkingSpot.save()
}
_parkingSpot.values.splice(_parkingSpot.values.findIndex((v) => v.equals(val.id)), 1)
await _parkingSpot.save()
await LocationValue.deleteMany({ $and: [{ _id: { $in: _parkingSpot.values } }, { _id: { $in: valuesIds } }] })
}
}
Expand Down

0 comments on commit 048455e

Please sign in to comment.