Skip to content

Commit e07dad3

Browse files
committed
fix: test simplification to ensure no redownloads
1 parent a9eb21a commit e07dad3

File tree

6 files changed

+15
-22
lines changed

6 files changed

+15
-22
lines changed

api/src/unraid-api/unraid-file-modifier/file-modification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export abstract class FileModification {
1515
abstract id: string;
1616
public abstract readonly filePath: string;
1717

18-
protected constructor(protected readonly logger: Logger) {}
18+
public constructor(protected readonly logger: Logger) {}
1919

2020
// This is the main method that child classes need to implement
2121
protected abstract generatePatch(): Promise<string>;

api/src/unraid-api/unraid-file-modifier/modifications/__test__/generic-modification.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import { FileModification } from '@app/unraid-api/unraid-file-modifier/file-modi
88
import DefaultPageLayoutModification from '@app/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification';
99
import NotificationsPageModification from '@app/unraid-api/unraid-file-modifier/modifications/notifications-page.modification';
1010
import SSOFileModification from '@app/unraid-api/unraid-file-modifier/modifications/sso.modification';
11+
import { existsSync } from 'fs';
1112

1213
interface ModificationTestCase {
13-
ModificationClass: new (logger: Logger) => FileModification;
14+
ModificationClass: typeof FileModification;
1415
fileUrl: string;
1516
}
1617

@@ -37,8 +38,13 @@ async function testModification(testCase: ModificationTestCase) {
3738
const fileName = basename(testCase.fileUrl);
3839

3940
const path = resolve(__dirname, `../__fixtures__/downloaded/${fileName}`);
40-
const originalContent = await fetch(testCase.fileUrl).then((response) => response.text());
41-
await writeFile(path, originalContent);
41+
let originalContent = '';
42+
if (!existsSync(path)) {
43+
originalContent = await fetch(testCase.fileUrl).then((response) => response.text());
44+
await writeFile(path, originalContent);
45+
} else {
46+
originalContent = await readFile(path, 'utf-8');
47+
}
4248

4349
expect(originalContent.length).toBeGreaterThan(0);
4450

api/src/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ export default class DefaultPageLayoutModification extends FileModification {
1313
public readonly filePath: string =
1414
'/usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php';
1515

16-
constructor(logger: Logger) {
17-
super(logger);
18-
}
19-
2016
private addToaster(source: string): string {
2117
if (source.includes('unraid-toaster')) {
2218
return source;

api/src/unraid-api/unraid-file-modifier/modifications/notifications-page.modification.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ export default class NotificationsPageModification extends FileModification {
1212
id: string = 'notifications-page';
1313
public readonly filePath: string = '/usr/local/emhttp/plugins/dynamix/Notifications.page';
1414

15-
constructor(logger: Logger) {
16-
super(logger);
17-
}
18-
1915
protected async generatePatch(): Promise<string> {
2016
const fileContent = await readFile(this.filePath, 'utf-8');
2117

api/src/unraid-api/unraid-file-modifier/modifications/sso.modification.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ export default class SSOFileModification extends FileModification {
77
id: string = 'sso';
88
public readonly filePath: string = '/usr/local/emhttp/plugins/dynamix/include/.login.php';
99

10-
constructor(logger: Logger) {
11-
super(logger);
12-
}
13-
1410
protected async generatePatch(): Promise<string> {
1511
// Define the new PHP function to insert
1612
/* eslint-disable no-useless-escape */

api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.service.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Injectable, Logger, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
2+
3+
import { FileModification } from '@app/unraid-api/unraid-file-modifier/file-modification';
24
import AuthRequestModification from '@app/unraid-api/unraid-file-modifier/modifications/auth-request.modification';
35
import DefaultPageLayoutModification from '@app/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification';
46
import { LogRotateModification } from '@app/unraid-api/unraid-file-modifier/modifications/log-rotate.modification';
57
import NotificationsPageModification from '@app/unraid-api/unraid-file-modifier/modifications/notifications-page.modification';
68
import SSOFileModification from '@app/unraid-api/unraid-file-modifier/modifications/sso.modification';
7-
import { FileModification } from '@app/unraid-api/unraid-file-modifier/file-modification';
89

910
@Injectable()
1011
export class UnraidFileModificationService implements OnModuleInit, OnModuleDestroy {
@@ -17,11 +18,9 @@ export class UnraidFileModificationService implements OnModuleInit, OnModuleDest
1718
const mods = await this.loadModifications();
1819
await this.applyModifications(mods);
1920
} catch (err) {
20-
if (err instanceof Error) {
21-
this.logger.error(`Failed to apply modifications: ${err.message}`);
22-
} else {
23-
this.logger.error('Failed to apply modifications: Unknown error');
24-
}
21+
this.logger.error(
22+
`Failed to apply modifications: ${err instanceof Error ? err.message : 'Unknown error'}`
23+
);
2524
}
2625
}
2726

0 commit comments

Comments
 (0)