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