Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import MigrateSignature from './migrate/Signature';
import MigrateByKeySignature from './migrateByKey/Signature';
import RollbackSignature from './rollback/Signature';
import RollbackByKeySignature from './rollbackByKey/Signature';
import Migration from './utils/types/Migration';

export default interface Facade {
readonly clearMigrations: () => Promise<void>;
readonly getMigrations: () => Promise<Migration[]>;
readonly migrate: MigrateSignature;
readonly migrateByKey: MigrateByKeySignature;
readonly rollback: RollbackSignature;
Expand Down
6 changes: 5 additions & 1 deletion src/factory.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import * as sourceMapSupport from 'source-map-support';
sourceMapSupport.install();

import factory from './factory';
import factoryTest from './factoryTest';
import testRepoFactory from './utils/tests/testRepoFactory';

factoryTest(testRepoFactory);
factoryTest((migrations) => {
const log = () => null;
return factory({ log, repo: testRepoFactory(migrations) });
});
2 changes: 2 additions & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import rollbackByKey from './rollbackByKey';

export default (config: FacadeConfig): Facade => {
return {
clearMigrations: config.repo.clearMigrations,
getMigrations: config.repo.getMigrations,
migrate: migrate(config),
migrateByKey: migrateByKey(config),
rollback: rollback(config),
Expand Down
12 changes: 6 additions & 6 deletions src/factoryTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import rollbackTest from './rollback/test';
import rollbackByKeyTest from './rollbackByKey/test';
import TestFactory from './utils/tests/TestFactory';

const testFactory: TestFactory = (repoFactory) => {
const testFactory: TestFactory = (serviceFactory) => {
describe('factory', () => {
beforeEach(async () => {
await repoFactory([]).clearMigrations();
await serviceFactory([]).clearMigrations();
});

migrateTest(repoFactory);
migrateByKeyTest(repoFactory);
rollbackTest(repoFactory);
rollbackByKeyTest(repoFactory);
migrateTest(serviceFactory);
migrateByKeyTest(serviceFactory);
rollbackTest(serviceFactory);
rollbackByKeyTest(serviceFactory);
});
};

Expand Down
13 changes: 3 additions & 10 deletions src/migrate/test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import * as assert from 'assert';
import * as assertRejects from 'assert-rejects';
import 'mocha'; // tslint:disable-line:no-import-side-effect
import factory from '../factory';
import DuplicateKeyError from '../utils/errors/DuplicateKeyError';
import FailingMigrationError from '../utils/errors/FailingMigrationError';
import assertLocked from '../utils/tests/assertLocked';
import createMigrationProcess from '../utils/tests/createMigrationProcess';
import createTestUpMigration from '../utils/tests/createTestUpMigration';
import TestFactory from '../utils/tests/TestFactory';
import Migration from '../utils/types/Migration';

const testMigrate: TestFactory = (repoFactory) => {
const testMigrate: TestFactory = (createService) => {
const successfulMigration = createTestUpMigration(undefined, 'successfulMigration');
const failingMigration = createTestUpMigration(() => { throw new Error(); }, 'failingMigration');
const skippableKey = 'skippableMigration';
const skippableMigration = createTestUpMigration(undefined, skippableKey);

const createService = (migrations: Migration[] = []) => {
const log = () => null;
return factory({ log, repo: repoFactory(migrations) });
};

describe('migrate', () => {
it('should not error when there are no migrations', async () => {
const service = createService();
const service = createService([]);
await service.migrate();
});

Expand Down Expand Up @@ -82,7 +75,7 @@ const testMigrate: TestFactory = (repoFactory) => {
});

it('should error when migrations are locked', async () => {
const service = createService();
const service = createService([]);
await assertLocked([service.migrate(), service.migrate()]);
});
});
Expand Down
11 changes: 2 additions & 9 deletions src/migrateByKey/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as assert from 'assert';
import * as assertRejects from 'assert-rejects';
import 'mocha'; // tslint:disable-line:no-import-side-effect
import factory from '../factory';
import DuplicateKeyError from '../utils/errors/DuplicateKeyError';
import FailingMigrationError from '../utils/errors/FailingMigrationError';
import MissingMigrationError from '../utils/errors/MissingMigrationError';
Expand All @@ -10,20 +9,14 @@ import assertLocked from '../utils/tests/assertLocked';
import createMigrationProcess from '../utils/tests/createMigrationProcess';
import createTestUpMigration, { testMigrationKey } from '../utils/tests/createTestUpMigration';
import TestFactory from '../utils/tests/TestFactory';
import Migration from '../utils/types/Migration';

const testMigrateByKey: TestFactory = (repoFactory) => {
const testMigrateByKey: TestFactory = (createService) => {
const successfulMigration = createTestUpMigration();
const failingMigration = createTestUpMigration(() => { throw new Error(); });

const createService = (migrations: Migration[] = []) => {
const log = () => null;
return factory({ log, repo: repoFactory(migrations) });
};

describe('migrateByKey', () => {
it('should error when the migration is missing', async () => {
const service = createService();
const service = createService([]);
const promise = service.migrateByKey({ key: 'missingKey' });
await assertRejects(promise, MissingMigrationError);
});
Expand Down
15 changes: 4 additions & 11 deletions src/rollback/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@
import * as assert from 'assert';
import * as assertRejects from 'assert-rejects';
import 'mocha'; // tslint:disable-line:no-import-side-effect
import factory from '../factory';
import DuplicateKeyError from '../utils/errors/DuplicateKeyError';
import FailingMigrationError from '../utils/errors/FailingMigrationError';
import MissingMigrationError from '../utils/errors/MissingMigrationError';
import assertLocked from '../utils/tests/assertLocked';
import createMigrationProcess from '../utils/tests/createMigrationProcess';
import createTestDownMigration from '../utils/tests/createTestDownMigration';
import TestFactory from '../utils/tests/TestFactory';
import Migration from '../utils/types/Migration';

const testRollback: TestFactory = (repoFactory) => {
const testRollback: TestFactory = (createService) => {
const successfulMigration = createTestDownMigration(undefined, 'successfulMigration');
const failingMigration = createTestDownMigration(() => {
throw new Error();
}, 'failingMigration');
const unskippableKey = 'unskippableMigration';
const unskippableMigration = createTestDownMigration(undefined, unskippableKey);

const createService = (migrations: Migration[] = []) => {
const log = () => null;
return factory({ log, repo: repoFactory(migrations) });
};

describe('rollback', () => {
it('should not error when there are no migrations', async () => {
const service = createService();
const service = createService([]);
await service.rollback();
});

Expand All @@ -40,7 +33,7 @@ const testRollback: TestFactory = (repoFactory) => {

it('should error when a processed migration is missing', async () => {
await createService([successfulMigration]).migrate();
const promise = createService().rollback();
const promise = createService([]).rollback();
await assertRejects(promise, MissingMigrationError);
});

Expand Down Expand Up @@ -98,7 +91,7 @@ const testRollback: TestFactory = (repoFactory) => {
});

it('should error when migrations are locked', async () => {
const service = createService();
const service = createService([]);
await assertLocked([service.rollback(), service.rollback()]);
});
});
Expand Down
11 changes: 2 additions & 9 deletions src/rollbackByKey/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as assert from 'assert';
import * as assertRejects from 'assert-rejects';
import 'mocha'; // tslint:disable-line:no-import-side-effect
import factory from '../factory';
import DuplicateKeyError from '../utils/errors/DuplicateKeyError';
import FailingMigrationError from '../utils/errors/FailingMigrationError';
import UnprocessedMigrationError from '../utils/errors/UnprocessedMigrationError';
Expand All @@ -10,20 +9,14 @@ import createMigrationProcess from '../utils/tests/createMigrationProcess';
import createTestDownMigration from '../utils/tests/createTestDownMigration';
import { testMigrationKey } from '../utils/tests/createTestUpMigration';
import TestFactory from '../utils/tests/TestFactory';
import Migration from '../utils/types/Migration';

const testRollbackByKey: TestFactory = (repoFactory) => {
const testRollbackByKey: TestFactory = (createService) => {
const successfulMigration = createTestDownMigration();
const failingMigration = createTestDownMigration(() => { throw new Error(); });

const createService = (migrations: Migration[] = []) => {
const log = () => null;
return factory({ log, repo: repoFactory(migrations) });
};

describe('rollbackByKey', () => {
it('should error when the migration is missing', async () => {
const service = createService();
const service = createService([]);
const promise = service.rollbackByKey({ key: 'missingKey' });
await assertRejects(promise, UnprocessedMigrationError);
});
Expand Down
4 changes: 2 additions & 2 deletions src/utils/tests/TestFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import RepoFacade from '../../RepoFacade';
import Facade from '../../Facade';
import Migration from '../types/Migration';

type TestFactory = (repoFactory: (migrations: Migration[]) => RepoFacade) => void;
type TestFactory = (serviceFactory: (migrations: Migration[]) => Facade) => void;

export default TestFactory;