Skip to content

Commit

Permalink
fix: Moves testRepoFactory for use in testing presenters.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryasmi committed Mar 14, 2018
1 parent 339b6b4 commit a045e9e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 38 deletions.
40 changes: 2 additions & 38 deletions src/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
43 changes: 43 additions & 0 deletions src/utils/tests/testRepoFactory.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit a045e9e

Please sign in to comment.