fix: file modification service fixes

This commit is contained in:
Eli Bosley
2025-01-28 13:58:47 -05:00
parent 8483143a40
commit e4ebfc8a13
2 changed files with 28 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ describe('AuthService', () => {
description: 'Test API Key Description',
roles: [Role.GUEST, Role.CONNECT],
createdAt: new Date().toISOString(),
permissions: [],
};
const mockApiKeyWithSecret: ApiKeyWithSecret = {

View File

@@ -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();
});
});