Skip to content

Commit 42dc4dc

Browse files
committed
trigger integrity check correctly
1 parent d23f612 commit 42dc4dc

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/modules/games/files.service.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,26 @@ describe("FilesService", () => {
381381
).rejects.toThrow(NotFoundException);
382382
});
383383
});
384+
385+
describe("index", () => {
386+
it("should trigger integrity check when file stats are missing", async () => {
387+
jest.useFakeTimers();
388+
const localService = new FilesService(
389+
gamesService,
390+
metadataService,
391+
schedulerRegistry,
392+
gameVersionRepository as any,
393+
);
394+
const checkIntegritySpy = jest
395+
.spyOn(localService as any, "checkIntegrity")
396+
.mockResolvedValue([]);
397+
398+
await (localService as any).index("/tmp/test-files/My Game.zip");
399+
jest.advanceTimersByTime(5000);
400+
await Promise.resolve();
401+
402+
expect(checkIntegritySpy).toHaveBeenCalledTimes(1);
403+
jest.useRealTimers();
404+
});
405+
});
384406
});

src/modules/games/files.service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,15 @@ export class FilesService implements OnApplicationBootstrap {
267267

268268
/** Indexes a single file and updates the database accordingly. */
269269
private async index(path: string, stats?: Stats, skipIntegrityCheck = false) {
270+
if (!path || !this.isValidFilePath(path)) {
271+
return;
272+
}
273+
270274
const size = BigInt(stats?.size || 0);
271-
if (!size || !path || !this.isValidFilePath(path)) {
275+
if (!size) {
276+
if (!skipIntegrityCheck) {
277+
this.runDebouncedIntegrityCheck();
278+
}
272279
return;
273280
}
274281

0 commit comments

Comments
 (0)