diff --git a/api/src/unraid-api/auth/auth.service.spec.ts b/api/src/unraid-api/auth/auth.service.spec.ts index 96102ea1d..f29fdd01b 100644 --- a/api/src/unraid-api/auth/auth.service.spec.ts +++ b/api/src/unraid-api/auth/auth.service.spec.ts @@ -24,6 +24,7 @@ describe('AuthService', () => { description: 'Test API Key Description', roles: [Role.GUEST, Role.CONNECT], createdAt: new Date().toISOString(), + permissions: [], }; const mockApiKeyWithSecret: ApiKeyWithSecret = { diff --git a/api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.spec.ts b/api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.spec.ts index f8c1096ad..fd3284948 100644 --- a/api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.spec.ts +++ b/api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.spec.ts @@ -1,7 +1,7 @@ import { Logger } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; -import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; import { FileModification, @@ -99,4 +99,30 @@ describe('FileModificationService', () => { expect(mockLogger.log).toHaveBeenNthCalledWith(4, 'Rolling back modification: test'); expect(mockLogger.log).toHaveBeenNthCalledWith(5, 'Modification rolled back successfully: test'); }); + + it('should handle errors during rollback', async () => { + const errorMod = new TestFileModification(vi.fn(), () => + Promise.reject(new Error('Rollback failed')) + ); + await service.applyModification(errorMod); + await service.rollbackAll(); + expect(mockLogger.error).toHaveBeenCalled(); + }); + + it('should handle concurrent modifications', async () => { + const mods = [ + new TestFileModification(vi.fn(), vi.fn()), + new TestFileModification(vi.fn(), vi.fn()), + ]; + await Promise.all(mods.map((mod) => service.applyModification(mod))); + await service.rollbackAll(); + mods.forEach((mod) => { + expect(mod.rollbackImplementation).toHaveBeenCalled(); + }); + }); + + afterEach(async () => { + await service.rollbackAll(); + vi.clearAllMocks(); + }); });