Skip to content

Commit e70f3d0

Browse files
committed
added tests for PR #406
1 parent 42dc4dc commit e70f3d0

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
### Changes
1212

1313
- Updated automatic Web UI version selection: if no compatible stable release is found, the backend now falls back to the nearest newer stable release before falling back to `unstable`.
14+
- Added regex-based indexing exclusion filters: `GAMES_SEARCH_EXCLUDE_FILE_REGEX` and `GAMES_SEARCH_EXCLUDE_DIR_REGEX`.
15+
16+
### Thanks
17+
18+
- @AlmostEasyGoing
1419

1520
## 16.3.0
1621

@@ -37,6 +42,18 @@
3742
- Migrated backend configuration to NestJS Config (`@nestjs/config`) as the global config source.
3843
- Added YAML-based configuration support via `config.yaml` / `config.yml` in the config volume (`VOLUMES_CONFIG`) with precedence: `*_FILE` > env > YAML > defaults.
3944

45+
### Thanks
46+
47+
- @AlmostEasyGoing
48+
- @brokenglasszero
49+
- @Toylerrr
50+
- @Z0y6h0kS9X
51+
- @dandroid213
52+
- @spaceboy1234
53+
- @binarygeek119
54+
- @KawaKode
55+
- @ShadowPeo
56+
4057
## 16.2.0
4158

4259
### Changes

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ jest.mock("fs-extra", () => ({
5151

5252
describe("FilesService", () => {
5353
let service: FilesService;
54+
let configuration: {
55+
GAMES: {
56+
SEARCH_EXCLUDE_FILE_REGEX?: RegExp;
57+
SEARCH_EXCLUDE_DIR_REGEX?: RegExp;
58+
};
59+
};
5460
let gamesService: jest.Mocked<GamesService>;
5561
let metadataService: jest.Mocked<MetadataService>;
5662
let schedulerRegistry: jest.Mocked<SchedulerRegistry>;
@@ -69,6 +75,9 @@ describe("FilesService", () => {
6975

7076
beforeEach(() => {
7177
fsExtra = jest.requireMock("fs-extra");
78+
configuration = jest.requireMock("../../configuration").default;
79+
configuration.GAMES.SEARCH_EXCLUDE_FILE_REGEX = undefined;
80+
configuration.GAMES.SEARCH_EXCLUDE_DIR_REGEX = undefined;
7281

7382
gamesService = {
7483
findOneByGameIdOrFail: jest.fn(),
@@ -403,4 +412,30 @@ describe("FilesService", () => {
403412
jest.useRealTimers();
404413
});
405414
});
415+
416+
describe("search exclude regex filters", () => {
417+
it("should exclude files matching GAMES_SEARCH_EXCLUDE_FILE_REGEX", () => {
418+
configuration.GAMES.SEARCH_EXCLUDE_FILE_REGEX = /sample/i;
419+
420+
expect((service as any).shouldIncludeFile("My Sample Game.zip")).toBe(
421+
false,
422+
);
423+
expect((service as any).shouldIncludeFile("My Real Game.zip")).toBe(true);
424+
});
425+
426+
it("should exclude directories matching GAMES_SEARCH_EXCLUDE_DIR_REGEX", () => {
427+
configuration.GAMES.SEARCH_EXCLUDE_DIR_REGEX = /^ignored$/i;
428+
429+
expect((service as any).shouldIncludeDirectory("ignored")).toBe(false);
430+
expect((service as any).shouldIncludeDirectory("games")).toBe(true);
431+
});
432+
433+
it("should still apply normal filename validation after regex checks", () => {
434+
configuration.GAMES.SEARCH_EXCLUDE_FILE_REGEX = /^ignore-/i;
435+
436+
expect((service as any).shouldIncludeFile("ignore-demo.zip")).toBe(false);
437+
expect((service as any).shouldIncludeFile("valid-title.zip")).toBe(true);
438+
expect((service as any).shouldIncludeFile("valid-title.txt")).toBe(false);
439+
});
440+
});
406441
});

src/modules/games/game-versions.controller.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
ApiNoContentResponse,
1717
ApiOkResponse,
1818
ApiOperation,
19+
ApiParam,
1920
ApiSecurity,
2021
ApiTags,
2122
} from "@nestjs/swagger";
@@ -42,6 +43,18 @@ export class GameVersionsController {
4243
) {}
4344

4445
@Delete(":game_id/versions/:version_id")
46+
@ApiParam({
47+
name: "game_id",
48+
type: Number,
49+
description: "numeric id of the game",
50+
example: 42,
51+
})
52+
@ApiParam({
53+
name: "version_id",
54+
type: Number,
55+
description: "numeric id of the game version",
56+
example: 7,
57+
})
4558
@ApiOperation({
4659
summary: "deletes a specific game version file from disk",
4760
description:
@@ -61,6 +74,18 @@ export class GameVersionsController {
6174
}
6275

6376
@Get(":game_id/versions/:version_id")
77+
@ApiParam({
78+
name: "game_id",
79+
type: Number,
80+
description: "numeric id of the game",
81+
example: 42,
82+
})
83+
@ApiParam({
84+
name: "version_id",
85+
type: Number,
86+
description: "numeric id of the game version",
87+
example: 7,
88+
})
6489
@ApiHeader({
6590
name: "X-Download-Speed-Limit",
6691
required: false,

0 commit comments

Comments
 (0)