fix: basic test fixed

This commit is contained in:
Eli Bosley
2025-01-28 11:47:44 -05:00
parent bb37140d40
commit bddda823e1
3 changed files with 15 additions and 10 deletions

View File

@@ -1,7 +1,8 @@
import { Module } from '@nestjs/common';
import { FileModificationService } from './unraid-file-modifier.service';
import { UnraidFileModificationService } from './unraid-file-modifier.service';
@Module({
providers: [FileModificationService]
providers: [UnraidFileModificationService],
})
export class UnraidFileModifierModule {}

View File

@@ -19,8 +19,8 @@ export interface FileModification {
// Step 2: Create a FileModificationService
@Injectable()
export class FileModificationService implements OnModuleInit, OnModuleDestroy {
private readonly logger = new Logger(FileModificationService.name);
export class UnraidFileModificationService implements OnModuleInit, OnModuleDestroy {
private readonly logger = new Logger(UnraidFileModificationService.name);
private history: FileModification[] = []; // Keeps track of applied modifications
async onModuleInit() {
@@ -71,12 +71,16 @@ export class FileModificationService implements OnModuleInit, OnModuleDestroy {
try {
const shouldApplyWithReason = await modification.shouldApply();
if (shouldApplyWithReason.shouldApply) {
this.logger.log(`Applying modification: ${modification.id} - ${shouldApplyWithReason.reason}`);
this.logger.log(
`Applying modification: ${modification.id} - ${shouldApplyWithReason.reason}`
);
await modification.apply();
this.history.push(modification); // Store modification in history
this.logger.log(`Modification applied successfully: ${modification.id}`);
} else {
this.logger.log(`Skipping modification: ${modification.id} - ${shouldApplyWithReason.reason}`);
this.logger.log(
`Skipping modification: ${modification.id} - ${shouldApplyWithReason.reason}`
);
}
} catch (error) {
if (error instanceof Error) {

View File

@@ -1,16 +1,16 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UnraidFileModifierService } from './unraid-file-modifier.service';
import { UnraidFileModificationService } from '@app/unraid-api/unraid-file-modifier/unraid-file-modifier.service';
describe('FileModificationService', () => {
let service: UnraidFileModifierService;
let service: UnraidFileModificationService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [UnraidFileModifierService],
providers: [UnraidFileModificationService],
}).compile();
service = module.get<UnraidFileModifierService>(UnraidFileModifierService);
service = module.get<UnraidFileModificationService>(UnraidFileModificationService);
});
it('should be defined', () => {