Skip to content

Commit

Permalink
Add migrator test for migrate:down
Browse files Browse the repository at this point in the history
  • Loading branch information
leeallen337 committed May 29, 2019
1 parent aafdd10 commit 6d7ec60
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions test/integration/migrate/index.js
Expand Up @@ -582,6 +582,72 @@ module.exports = function(knex) {
});
});

describe('knex.migrate.down', () => {
beforeEach(() => {
return knex.migrate.latest({
directory: ['test/integration/migrate/test'],
});
});

afterEach(() => {
return knex.migrate.rollback(
{ directory: ['test/integration/migrate/test'] },
true
);
});

it('should only undo the last migration that was run if all migrations have run', function() {
return knex.migrate
.down({
directory: ['test/integration/migrate/test'],
})
.then(() => {
return knex('knex_migrations')
.select('*')
.then((data) => {
expect(data).to.have.length(1);
expect(path.basename(data[0].name)).to.equal(
'20131019235242_migration_1.js'
);
});
});
});

it('should only undo the last migration that was run if there are other migrations that have not yet run', function() {
return knex.migrate
.down({
directory: ['test/integration/migrate/test'],
})
.then(() => {
return knex.migrate
.down({
directory: ['test/integration/migrate/test'],
})
.then(() => {
return knex('knex_migrations')
.select('*')
.then((data) => {
expect(data).to.have.length(0);
});
});
});
});

it('should not error if all migrations have already been undone', function() {
return knex.migrate
.rollback({ directory: ['test/integration/migrate/test'] }, true)
.then(() => {
return knex.migrate
.down({
directory: ['test/integration/migrate/test'],
})
.then((data) => {
expect(data).to.be.an('array');
});
});
});
});

after(function() {
rimraf.sync(path.join(__dirname, './migration'));
});
Expand Down

0 comments on commit 6d7ec60

Please sign in to comment.