resonatecoop / api

The one Resonate API to rule them all

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automatically reset database before and after each test suite

simonv3 opened this issue · comments

commented

I think it'd be a good idea, for the sake of "knowing what's in the database during tests" if we reset the database before and after each test suite.

Check out this SO issue that points the way:
https://stackoverflow.com/a/71730531/154392

Basically I'm thinking of creating a file like MockAccessToken that's called resetDB.

Then in the resetDB file have a before and after that run something like:

var seedsConfig = {
  storage: "sequelize",
  storageOptions: {
    sequelize: models.sequelize,
    modelName: 'SequelizeData' // Or whatever you want to name the seeder storage table
  },
  migrations: {
    params: [
      models.sequelize.getQueryInterface(),
      models.sequelize.constructor
    ],
    path: "./seeders/test", // path to folder containing seeds
    pattern: /\.js$/
  }
};

before(async () => {
  var seeder = new Umzug(seedsConfig);
  await seeder.down({ to: 0 });
  await seeder.up();
})

obviously that's untested code, but just wanted to put it out there.