Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Nov 18, 2024
1 parent d8e4d52 commit aa1815f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
23 changes: 3 additions & 20 deletions api/scripts/db.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
import 'dotenv/config'
// import * as bookcarsTypes from ':bookcars-types'
import * as env from '../src/config/env.config'
import * as logger from '../src/common/logger'
import * as databaseHelper from '../src/common/databaseHelper'
import Car from '../src/models/Car'
// import User from '../src/models/User'

if (
await databaseHelper.connect(env.DB_URI, env.DB_SSL, env.DB_DEBUG)
) {
const cars = await Car.find({})

for (const car of cars) {
if (('price' in car) && car.price) {
car.dailyPrice = Number(car.price)
car.discountedDailyPrice = null
car.biWeeklyPrice = null
car.discountedBiWeeklyPrice = null
car.weeklyPrice = null
car.discountedWeeklyPrice = null
car.monthlyPrice = null
car.discountedMonthlyPrice = null
car.price = undefined
await car.save()
console.log(`${car.id} affected`)
}
}

await databaseHelper.close()
logger.info('MongoDB connection closed')
logger.info('Database connection closed')
process.exit(0)
}
31 changes: 31 additions & 0 deletions api/scripts/price.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'dotenv/config'
import * as env from '../src/config/env.config'
import * as logger from '../src/common/logger'
import * as databaseHelper from '../src/common/databaseHelper'
import Car from '../src/models/Car'

if (
await databaseHelper.connect(env.DB_URI, env.DB_SSL, env.DB_DEBUG)
) {
const cars = await Car.find({})

for (const car of cars) {
if (('price' in car) && car.price) {
car.dailyPrice = Number(car.price)
car.discountedDailyPrice = null
car.biWeeklyPrice = null
car.discountedBiWeeklyPrice = null
car.weeklyPrice = null
car.discountedWeeklyPrice = null
car.monthlyPrice = null
car.discountedMonthlyPrice = null
car.price = undefined
await car.save()
console.log(`${car.id} affected`)
}
}

await databaseHelper.close()
logger.info('MongoDB connection closed')
process.exit(0)
}
2 changes: 1 addition & 1 deletion api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if (
server.close(async () => {
logger.info(`HTTP${env.HTTPS ? 'S' : ''} server closed`)
await databaseHelper.close(true)
logger.info('MongoDB connection closed')
logger.info('Database connection closed')
process.exit(0)
})
}
Expand Down
1 change: 1 addition & 0 deletions api/tests/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default async function globalSetup() {
}
if (mongoose.connection.readyState) {
await databaseHelper.close()
logger.info('Database connection closed')
}
}
} catch (err) {
Expand Down

0 comments on commit aa1815f

Please sign in to comment.