refactor: rename project

This commit is contained in:
Carlos Valente
2024-06-27 22:36:51 +02:00
committed by Carlos Valente
parent c9ef8d55c1
commit 46195fc043
8 changed files with 58 additions and 64 deletions
@@ -1,4 +1,4 @@
import { deleteProjectFile, duplicateProjectFile } from '../ProjectService.js';
import { deleteProjectFile, duplicateProjectFile, renameProjectFile } from '../ProjectService.js';
import { appStateProvider } from '../../app-state-service/AppStateService.js';
import { doesProjectExist } from '../projectServiceUtils.js';
import { Mock } from 'vitest';
@@ -54,3 +54,20 @@ describe('duplicateProjectFile', () => {
);
});
});
describe('renameProjectFile', () => {
it('throws an error if origin project does not exist', async () => {
(doesProjectExist as Mock).mockReturnValue(false);
await expect(renameProjectFile('does not exist', 'doesnt matter')).rejects.toThrow('Project file not found');
});
it('throws an error if new file name is already a project', async () => {
// current project exists
(doesProjectExist as Mock).mockReturnValueOnce(true);
// new project exists
(doesProjectExist as Mock).mockReturnValueOnce(true);
expect(renameProjectFile('nonexistentProject', 'existingproject')).rejects.toThrow(
'Project file with name existingproject already exists',
);
});
});