Skip to content

Commit a045e9e

Browse files
committed
fix: Moves testRepoFactory for use in testing presenters.
1 parent 339b6b4 commit a045e9e

File tree

2 files changed

+45
-38
lines changed

2 files changed

+45
-38
lines changed

src/factory.test.ts

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,6 @@ import * as sourceMapSupport from 'source-map-support';
22
sourceMapSupport.install();
33

44
import factoryTest from './factoryTest';
5-
import LockedMigrationsError from './utils/errors/LockedMigrationsError';
6-
import ProcessedMigration from './utils/types/ProcessedMigration';
5+
import testRepoFactory from './utils/tests/testRepoFactory';
76

8-
let processedMigrations: ProcessedMigration[] = []; // tslint:disable-line:no-let
9-
let hasLockedMigrations = false; // tslint:disable-line:no-let
10-
11-
factoryTest((migrations) => {
12-
return {
13-
clearMigrations: async () => {
14-
processedMigrations = [];
15-
},
16-
getMigrations: async () => {
17-
return migrations;
18-
},
19-
getProcessedMigrations: async () => {
20-
return processedMigrations;
21-
},
22-
lockMigrations: async () => {
23-
if (hasLockedMigrations) {
24-
throw new LockedMigrationsError();
25-
}
26-
hasLockedMigrations = true;
27-
},
28-
removeProcessedMigration: async (key) => {
29-
processedMigrations = processedMigrations.filter((processedMigration) => {
30-
return processedMigration.key !== key;
31-
});
32-
},
33-
unlockMigrations: async () => {
34-
hasLockedMigrations = false;
35-
},
36-
updateProcessedMigration: async (migration) => {
37-
const unmatchedMigrations = processedMigrations.filter((processedMigration) => {
38-
return processedMigration.key !== migration.key;
39-
});
40-
processedMigrations = [...unmatchedMigrations, migration];
41-
},
42-
};
43-
});
7+
factoryTest(testRepoFactory);

src/utils/tests/testRepoFactory.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import RepoFacade from '../../RepoFacade';
2+
import LockedMigrationsError from '../errors/LockedMigrationsError';
3+
import Migration from '../types/Migration';
4+
import ProcessedMigration from '../types/ProcessedMigration';
5+
6+
let processedMigrations: ProcessedMigration[] = []; // tslint:disable-line:no-let
7+
let hasLockedMigrations = false; // tslint:disable-line:no-let
8+
9+
const testRepoFactory = (migrations: Migration[]): RepoFacade => {
10+
return {
11+
clearMigrations: async () => {
12+
processedMigrations = [];
13+
},
14+
getMigrations: async () => {
15+
return migrations;
16+
},
17+
getProcessedMigrations: async () => {
18+
return processedMigrations;
19+
},
20+
lockMigrations: async () => {
21+
if (hasLockedMigrations) {
22+
throw new LockedMigrationsError();
23+
}
24+
hasLockedMigrations = true;
25+
},
26+
removeProcessedMigration: async (key) => {
27+
processedMigrations = processedMigrations.filter((processedMigration) => {
28+
return processedMigration.key !== key;
29+
});
30+
},
31+
unlockMigrations: async () => {
32+
hasLockedMigrations = false;
33+
},
34+
updateProcessedMigration: async (migration) => {
35+
const unmatchedMigrations = processedMigrations.filter((processedMigration) => {
36+
return processedMigration.key !== migration.key;
37+
});
38+
processedMigrations = [...unmatchedMigrations, migration];
39+
},
40+
};
41+
};
42+
43+
export default testRepoFactory;

0 commit comments

Comments
 (0)