diff --git a/test/service/migrator.test.ts b/test/service/migrator.test.ts index 1d068e36..d500b721 100644 --- a/test/service/migrator.test.ts +++ b/test/service/migrator.test.ts @@ -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. @@ -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', () => {