Skip to content

Commit

Permalink
test(backend): group maplistservice tests better
Browse files Browse the repository at this point in the history
Evil indentation commit, just wrapping a jest block
  • Loading branch information
tsa96 committed Oct 23, 2024
1 parent b79360a commit 1eeb6c8
Showing 1 changed file with 42 additions and 38 deletions.
80 changes: 42 additions & 38 deletions apps/backend/src/app/modules/maps/map-list.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,55 +36,59 @@ describe('MapListService', () => {
db = module.get(EXTENDED_PRISMA_SERVICE);
});

it('should set version values based on files in storage', async () => {
fileStoreMock.listFileKeys.mockResolvedValueOnce([
'maplist/approved/1.dat'
]);
fileStoreMock.listFileKeys.mockResolvedValueOnce([
'maplist/submissions/15012024.dat'
]);

await service.onModuleInit();

expect(service['version']).toMatchObject({
[FlatMapList.APPROVED]: 1,
[FlatMapList.SUBMISSION]: 15012024
describe('onModuleInit', () => {
it('should set version values based on files in storage', async () => {
fileStoreMock.listFileKeys.mockResolvedValueOnce([
'maplist/approved/1.dat'
]);
fileStoreMock.listFileKeys.mockResolvedValueOnce([
'maplist/submissions/15012024.dat'
]);

await service.onModuleInit();

expect(service['version']).toMatchObject({
[FlatMapList.APPROVED]: 1,
[FlatMapList.SUBMISSION]: 15012024
});

expect(fileStoreMock.deleteFiles).not.toHaveBeenCalled();
});

expect(fileStoreMock.deleteFiles).not.toHaveBeenCalled();
});
it('should set version to 0 when no versions exist in storage', async () => {
await service.onModuleInit();

it('should set version to 0 when no versions exist in storage', async () => {
await service.onModuleInit();
expect(service['version']).toMatchObject({
[FlatMapList.APPROVED]: 0,
[FlatMapList.SUBMISSION]: 0
});

expect(service['version']).toMatchObject({
[FlatMapList.APPROVED]: 0,
[FlatMapList.SUBMISSION]: 0
expect(fileStoreMock.deleteFiles).not.toHaveBeenCalled();
});

expect(fileStoreMock.deleteFiles).not.toHaveBeenCalled();
});
it('should pick most recent when multiple versions exist in storage, and wipe old versions', async () => {
fileStoreMock.listFileKeys.mockResolvedValueOnce([
'maplist/approved/4.dat',
'maplist/approved/5.dat',
'maplist/approved/3.dat',
'maplist/approved/1.dat'
]);

it('should pick most recent when multiple versions exist in storage, and wipe old versions', async () => {
fileStoreMock.listFileKeys.mockResolvedValueOnce([
'maplist/approved/4.dat',
'maplist/approved/5.dat',
'maplist/approved/3.dat',
'maplist/approved/1.dat'
]);
await service.onModuleInit();

await service.onModuleInit();
expect(service['version']).toMatchObject({
[FlatMapList.APPROVED]: 5,
[FlatMapList.SUBMISSION]: 0
});

expect(service['version']).toMatchObject({
[FlatMapList.APPROVED]: 5,
[FlatMapList.SUBMISSION]: 0
expect(fileStoreMock.deleteFiles).toHaveBeenCalledWith([
'maplist/approved/4.dat',
'maplist/approved/3.dat',
'maplist/approved/1.dat'
]);
});
});

expect(fileStoreMock.deleteFiles).toHaveBeenCalledWith([
'maplist/approved/4.dat',
'maplist/approved/3.dat',
'maplist/approved/1.dat'
]);
describe('updateMapList', () => {
// prettier-ignore
const storedMap = {
Expand Down

0 comments on commit 1eeb6c8

Please sign in to comment.