mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
fix: file modification service fixes
This commit is contained in:
@@ -24,6 +24,7 @@ describe('AuthService', () => {
|
|||||||
description: 'Test API Key Description',
|
description: 'Test API Key Description',
|
||||||
roles: [Role.GUEST, Role.CONNECT],
|
roles: [Role.GUEST, Role.CONNECT],
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
|
permissions: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockApiKeyWithSecret: ApiKeyWithSecret = {
|
const mockApiKeyWithSecret: ApiKeyWithSecret = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Logger } from '@nestjs/common';
|
import { Logger } from '@nestjs/common';
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
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 {
|
import {
|
||||||
FileModification,
|
FileModification,
|
||||||
@@ -99,4 +99,30 @@ describe('FileModificationService', () => {
|
|||||||
expect(mockLogger.log).toHaveBeenNthCalledWith(4, 'Rolling back modification: test');
|
expect(mockLogger.log).toHaveBeenNthCalledWith(4, 'Rolling back modification: test');
|
||||||
expect(mockLogger.log).toHaveBeenNthCalledWith(5, 'Modification rolled back successfully: 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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user