mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
fix: test simplification to ensure no redownloads
This commit is contained in:
@@ -15,7 +15,7 @@ export abstract class FileModification {
|
||||
abstract id: string;
|
||||
public abstract readonly filePath: string;
|
||||
|
||||
protected constructor(protected readonly logger: Logger) {}
|
||||
public constructor(protected readonly logger: Logger) {}
|
||||
|
||||
// This is the main method that child classes need to implement
|
||||
protected abstract generatePatch(): Promise<string>;
|
||||
|
||||
@@ -8,9 +8,10 @@ import { FileModification } from '@app/unraid-api/unraid-file-modifier/file-modi
|
||||
import DefaultPageLayoutModification from '@app/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification';
|
||||
import NotificationsPageModification from '@app/unraid-api/unraid-file-modifier/modifications/notifications-page.modification';
|
||||
import SSOFileModification from '@app/unraid-api/unraid-file-modifier/modifications/sso.modification';
|
||||
import { existsSync } from 'fs';
|
||||
|
||||
interface ModificationTestCase {
|
||||
ModificationClass: new (logger: Logger) => FileModification;
|
||||
ModificationClass: typeof FileModification;
|
||||
fileUrl: string;
|
||||
}
|
||||
|
||||
@@ -37,8 +38,13 @@ async function testModification(testCase: ModificationTestCase) {
|
||||
const fileName = basename(testCase.fileUrl);
|
||||
|
||||
const path = resolve(__dirname, `../__fixtures__/downloaded/${fileName}`);
|
||||
const originalContent = await fetch(testCase.fileUrl).then((response) => response.text());
|
||||
await writeFile(path, originalContent);
|
||||
let originalContent = '';
|
||||
if (!existsSync(path)) {
|
||||
originalContent = await fetch(testCase.fileUrl).then((response) => response.text());
|
||||
await writeFile(path, originalContent);
|
||||
} else {
|
||||
originalContent = await readFile(path, 'utf-8');
|
||||
}
|
||||
|
||||
expect(originalContent.length).toBeGreaterThan(0);
|
||||
|
||||
|
||||
@@ -13,10 +13,6 @@ export default class DefaultPageLayoutModification extends FileModification {
|
||||
public readonly filePath: string =
|
||||
'/usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php';
|
||||
|
||||
constructor(logger: Logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
private addToaster(source: string): string {
|
||||
if (source.includes('unraid-toaster')) {
|
||||
return source;
|
||||
|
||||
@@ -12,10 +12,6 @@ export default class NotificationsPageModification extends FileModification {
|
||||
id: string = 'notifications-page';
|
||||
public readonly filePath: string = '/usr/local/emhttp/plugins/dynamix/Notifications.page';
|
||||
|
||||
constructor(logger: Logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
protected async generatePatch(): Promise<string> {
|
||||
const fileContent = await readFile(this.filePath, 'utf-8');
|
||||
|
||||
|
||||
@@ -7,10 +7,6 @@ export default class SSOFileModification extends FileModification {
|
||||
id: string = 'sso';
|
||||
public readonly filePath: string = '/usr/local/emhttp/plugins/dynamix/include/.login.php';
|
||||
|
||||
constructor(logger: Logger) {
|
||||
super(logger);
|
||||
}
|
||||
|
||||
protected async generatePatch(): Promise<string> {
|
||||
// Define the new PHP function to insert
|
||||
/* eslint-disable no-useless-escape */
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Injectable, Logger, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
||||
|
||||
import { FileModification } from '@app/unraid-api/unraid-file-modifier/file-modification';
|
||||
import AuthRequestModification from '@app/unraid-api/unraid-file-modifier/modifications/auth-request.modification';
|
||||
import DefaultPageLayoutModification from '@app/unraid-api/unraid-file-modifier/modifications/default-page-layout.modification';
|
||||
import { LogRotateModification } from '@app/unraid-api/unraid-file-modifier/modifications/log-rotate.modification';
|
||||
import NotificationsPageModification from '@app/unraid-api/unraid-file-modifier/modifications/notifications-page.modification';
|
||||
import SSOFileModification from '@app/unraid-api/unraid-file-modifier/modifications/sso.modification';
|
||||
import { FileModification } from '@app/unraid-api/unraid-file-modifier/file-modification';
|
||||
|
||||
@Injectable()
|
||||
export class UnraidFileModificationService implements OnModuleInit, OnModuleDestroy {
|
||||
@@ -17,11 +18,9 @@ export class UnraidFileModificationService implements OnModuleInit, OnModuleDest
|
||||
const mods = await this.loadModifications();
|
||||
await this.applyModifications(mods);
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
this.logger.error(`Failed to apply modifications: ${err.message}`);
|
||||
} else {
|
||||
this.logger.error('Failed to apply modifications: Unknown error');
|
||||
}
|
||||
this.logger.error(
|
||||
`Failed to apply modifications: ${err instanceof Error ? err.message : 'Unknown error'}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user