From a045e9ebceef14c9ccbeedae8d13d192e5b0e2f5 Mon Sep 17 00:00:00 2001 From: Ryan Smith <0ryansmith1994@gmail.com> Date: Wed, 14 Mar 2018 13:37:44 +0000 Subject: [PATCH] fix: Moves testRepoFactory for use in testing presenters. --- src/factory.test.ts | 40 ++------------------------- src/utils/tests/testRepoFactory.ts | 43 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 38 deletions(-) create mode 100644 src/utils/tests/testRepoFactory.ts diff --git a/src/factory.test.ts b/src/factory.test.ts index 1f321576..cf694e31 100644 --- a/src/factory.test.ts +++ b/src/factory.test.ts @@ -2,42 +2,6 @@ import * as sourceMapSupport from 'source-map-support'; sourceMapSupport.install(); import factoryTest from './factoryTest'; -import LockedMigrationsError from './utils/errors/LockedMigrationsError'; -import ProcessedMigration from './utils/types/ProcessedMigration'; +import testRepoFactory from './utils/tests/testRepoFactory'; -let processedMigrations: ProcessedMigration[] = []; // tslint:disable-line:no-let -let hasLockedMigrations = false; // tslint:disable-line:no-let - -factoryTest((migrations) => { - return { - clearMigrations: async () => { - processedMigrations = []; - }, - getMigrations: async () => { - return migrations; - }, - getProcessedMigrations: async () => { - return processedMigrations; - }, - lockMigrations: async () => { - if (hasLockedMigrations) { - throw new LockedMigrationsError(); - } - hasLockedMigrations = true; - }, - removeProcessedMigration: async (key) => { - processedMigrations = processedMigrations.filter((processedMigration) => { - return processedMigration.key !== key; - }); - }, - unlockMigrations: async () => { - hasLockedMigrations = false; - }, - updateProcessedMigration: async (migration) => { - const unmatchedMigrations = processedMigrations.filter((processedMigration) => { - return processedMigration.key !== migration.key; - }); - processedMigrations = [...unmatchedMigrations, migration]; - }, - }; -}); +factoryTest(testRepoFactory); diff --git a/src/utils/tests/testRepoFactory.ts b/src/utils/tests/testRepoFactory.ts new file mode 100644 index 00000000..0f4586dc --- /dev/null +++ b/src/utils/tests/testRepoFactory.ts @@ -0,0 +1,43 @@ +import RepoFacade from '../../RepoFacade'; +import LockedMigrationsError from '../errors/LockedMigrationsError'; +import Migration from '../types/Migration'; +import ProcessedMigration from '../types/ProcessedMigration'; + +let processedMigrations: ProcessedMigration[] = []; // tslint:disable-line:no-let +let hasLockedMigrations = false; // tslint:disable-line:no-let + +const testRepoFactory = (migrations: Migration[]): RepoFacade => { + return { + clearMigrations: async () => { + processedMigrations = []; + }, + getMigrations: async () => { + return migrations; + }, + getProcessedMigrations: async () => { + return processedMigrations; + }, + lockMigrations: async () => { + if (hasLockedMigrations) { + throw new LockedMigrationsError(); + } + hasLockedMigrations = true; + }, + removeProcessedMigration: async (key) => { + processedMigrations = processedMigrations.filter((processedMigration) => { + return processedMigration.key !== key; + }); + }, + unlockMigrations: async () => { + hasLockedMigrations = false; + }, + updateProcessedMigration: async (migration) => { + const unmatchedMigrations = processedMigrations.filter((processedMigration) => { + return processedMigration.key !== migration.key; + }); + processedMigrations = [...unmatchedMigrations, migration]; + }, + }; +}; + +export default testRepoFactory;