Skip to content

Commit

Permalink
test: update readComponentsFiles test cases with improved error handl…
Browse files Browse the repository at this point in the history
…ing and path resolution

- Modified test cases to use dynamic space-specific paths
- Updated error assertion for file not found scenarios
- Enhanced error object validation with more detailed error information
- Refactored test setup to improve path flexibility and error handling
  • Loading branch information
alvarosabu committed Feb 10, 2025
1 parent b79677a commit 24fff77
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/commands/components/push/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe('push components actions', () => {
});

const result = await readComponentsFiles({
path: '/path/to/components/12345/',
path: '/path/to/',
from: '12345',
separateFiles: false,
verbose: false,
Expand All @@ -241,15 +241,15 @@ describe('push components actions', () => {

it('should read components from separate files successfully', async () => {
vol.fromJSON({
'/path/to/components/12345/component-name.json': JSON.stringify(mockComponent),
'/path/to/components/12345/component-name.preset.json': JSON.stringify([mockComponentPreset]),
'/path/to/components/12345/groups.json': JSON.stringify([mockComponentGroup]),
'/path/to/components/12345/tags.json': JSON.stringify([mockInternalTag]),
'/path/to/components/23746/component-name.json': JSON.stringify(mockComponent),
'/path/to/components/23746/component-name.preset.json': JSON.stringify([mockComponentPreset]),
'/path/to/components/23746/groups.json': JSON.stringify([mockComponentGroup]),
'/path/to/components/23746/tags.json': JSON.stringify([mockInternalTag]),
});

const result = await readComponentsFiles({
path: '/path/to/components/12345/',
from: '12345',
path: '/path/to/',
from: '23746',
separateFiles: true,
verbose: false,
});
Expand All @@ -271,8 +271,18 @@ describe('push components actions', () => {
})).rejects.toThrow(
expect.objectContaining({
name: 'File System Error',
message: 'The space folder \'non-existent\' doesn\'t exist yet. Please run \'storyblok components pull -s=non-existent\' first to fetch the components.',
errorId: 'file_not_found',
message: 'The file requested was not found',
cause: 'The file requested was not found',
code: 'ENOENT',
messageStack: expect.arrayContaining([
'Failed to read/parse file:',
'The file requested was not found',
]),
error: expect.objectContaining({
code: 'ENOENT',
message: expect.stringContaining('ENOENT: no such file or directory'),
}),
}),
);
});
Expand Down

0 comments on commit 24fff77

Please sign in to comment.