-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Moves testRepoFactory for use in testing presenters.
- Loading branch information
Showing
2 changed files
with
45 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |