diff --git a/api/jest.config.json b/api/jest.config.json index 182cee8..ee5b8e9 100644 --- a/api/jest.config.json +++ b/api/jest.config.json @@ -23,6 +23,7 @@ "!**/dist/**", "!**/__tests__/**" ], - "testTimeout": 120000, - "globalSetup": "./dist/__tests__/globalSetup.js" + "testTimeout": 180000, + "globalSetup": "./dist/__tests__/globalSetup.js", + "maxWorkers": 1 } diff --git a/api/src/common/databaseHelper.ts b/api/src/common/databaseHelper.ts index 6f5f302..4ee6956 100644 --- a/api/src/common/databaseHelper.ts +++ b/api/src/common/databaseHelper.ts @@ -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 } }] }) } } @@ -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 } }] }) } }