MongoHelper.js 689 B

1234567891011121314151617181920212223242526272829
  1. const { exec } = require('child_process')
  2. const { waitForDb, db } = require('../../../../app/src/infrastructure/mongodb')
  3. module.exports = {
  4. initialize() {
  5. before(waitForDb)
  6. before(function (done) {
  7. exec('bin/east migrate', (error, stdout, stderr) => {
  8. if (error) {
  9. throw error
  10. }
  11. done()
  12. })
  13. })
  14. afterEach(async function () {
  15. return Promise.all(
  16. Object.values(db).map(async collection => {
  17. if (collection === db.migrations) {
  18. // Do not clear the collection for tracking migrations.
  19. return
  20. }
  21. return collection.deleteMany({})
  22. })
  23. )
  24. })
  25. },
  26. }