mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
fix(core): Return default tags-mappings and folders value when file not found (#16747)
This commit is contained in:
committed by
GitHub
parent
a715f53eb6
commit
e163141b72
@@ -313,3 +313,44 @@ describe('isWorkflowModified', () => {
|
||||
expect(isWorkflowModified(local, remote)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('readTagAndMappingsFromSourceControlFile', () => {
|
||||
beforeEach(() => {
|
||||
// Reset module registry so we can unmock properly
|
||||
jest.resetModules();
|
||||
jest.unmock('node:fs/promises');
|
||||
});
|
||||
|
||||
it('should return default mapping if the file path is not valid', async () => {
|
||||
const filePath = 'invalid/path/tags-and-mappings.json';
|
||||
// Import the function after resetting modules
|
||||
const { readTagAndMappingsFromSourceControlFile } = await import(
|
||||
'@/environments.ee/source-control/source-control-helper.ee'
|
||||
);
|
||||
const result = await readTagAndMappingsFromSourceControlFile(filePath);
|
||||
expect(result).toEqual({
|
||||
tags: [],
|
||||
mappings: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('readFoldersFromSourceControlFile', () => {
|
||||
beforeEach(() => {
|
||||
// Reset module registry so we can unmock properly
|
||||
jest.resetModules();
|
||||
jest.unmock('node:fs/promises');
|
||||
});
|
||||
|
||||
it('should return default folders if the file path is not valid', async () => {
|
||||
const filePath = 'invalid/path/folders.json';
|
||||
// Import the function after resetting modules
|
||||
const { readFoldersFromSourceControlFile } = await import(
|
||||
'@/environments.ee/source-control/source-control-helper.ee'
|
||||
);
|
||||
const result = await readFoldersFromSourceControlFile(filePath);
|
||||
expect(result).toEqual({
|
||||
folders: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -54,16 +54,32 @@ export async function readTagAndMappingsFromSourceControlFile(file: string): Pro
|
||||
tags: TagEntity[];
|
||||
mappings: WorkflowTagMapping[];
|
||||
}> {
|
||||
return jsonParse<{ tags: TagEntity[]; mappings: WorkflowTagMapping[] }>(
|
||||
await fsReadFile(file, { encoding: 'utf8' }),
|
||||
{ fallbackValue: { tags: [], mappings: [] } },
|
||||
);
|
||||
try {
|
||||
return jsonParse<{ tags: TagEntity[]; mappings: WorkflowTagMapping[] }>(
|
||||
await fsReadFile(file, { encoding: 'utf8' }),
|
||||
{ fallbackValue: { tags: [], mappings: [] } },
|
||||
);
|
||||
} catch (error) {
|
||||
// Return fallback if file not found
|
||||
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
||||
return { tags: [], mappings: [] };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function readFoldersFromSourceControlFile(file: string): Promise<ExportedFolders> {
|
||||
return jsonParse<ExportedFolders>(await fsReadFile(file, { encoding: 'utf8' }), {
|
||||
fallbackValue: { folders: [] },
|
||||
});
|
||||
try {
|
||||
return jsonParse<ExportedFolders>(await fsReadFile(file, { encoding: 'utf8' }), {
|
||||
fallbackValue: { folders: [] },
|
||||
});
|
||||
} catch (error) {
|
||||
// Return fallback if file not found
|
||||
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
||||
return { folders: [] };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function sourceControlFoldersExistCheck(
|
||||
|
||||
Reference in New Issue
Block a user