Skip to content

Commit

Permalink
Add more tests for the migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
kabirbaidhya committed Mar 13, 2020
1 parent 2775818 commit c080a9f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/service/migrator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as migratorService from '../../src/service/migrator';

describe('SERVICE: migrator', () => {
describe('getSqlMigrationEntries', async () => {
it('should return the list of migrations under the directory.', async () => {
it('should return the list of valid migrations under the directory.', async () => {
const migrationPath = await mkdtemp();

// Populate migration files to a directory.
Expand All @@ -29,6 +29,24 @@ describe('SERVICE: migrator', () => {
// Test the migrations entries retrieved from the directory.
expect(result).to.deep.equal(['0001_mgr', '0002_mgr', '0003_mgr', '0004_mgr', '0005_mgr']);
});

it('should not return other files under the directory that are not migrations.', async () => {
const migrationPath = await mkdtemp();

// Populate migration files to a directory.
await Promise.all([
write(path.join(migrationPath, '0001_mgr.up.sql'), 'SELECT 1'),
write(path.join(migrationPath, '0002_mgr.down.sql'), 'SELECT 1'),
write(path.join(migrationPath, 'test.sql'), 'SELECT 2'),
write(path.join(migrationPath, 'migrate.sql'), 'SELECT 3'),
write(path.join(migrationPath, '.gitignore'), '')
]);

const result = await migratorService.getSqlMigrationNames(migrationPath);

// Test the migrations entries retrieved from the directory.
expect(result).to.deep.equal(['0001_mgr', '0002_mgr']);
});
});

describe('resolveSqlMigrations', () => {
Expand Down

0 comments on commit c080a9f

Please sign in to comment.