Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

Commit 5e6da59

Browse files
fix: fetchComponent when common name prefix
1 parent 7c570e6 commit 5e6da59

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/commands/components/pull/actions.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ const mockedComponents = [{
2424
color: null,
2525
internal_tags_list: ['tag'],
2626
internal_tag_ids: [1],
27+
}, {
28+
name: 'name-2',
29+
display_name: 'Name 2',
30+
created_at: '2021-08-09T12:00:00Z',
31+
updated_at: '2021-08-09T12:00:00Z',
32+
id: 12346,
33+
schema: { type: 'object' },
34+
color: null,
35+
internal_tags_list: [],
36+
internal_tag_ids: [],
2737
}];
2838

2939
const handlers = [
@@ -70,6 +80,16 @@ describe('pull components actions', () => {
7080
color: null,
7181
internal_tags_list: ['tag'],
7282
internal_tag_ids: [1],
83+
}, {
84+
name: 'name-2',
85+
display_name: 'Name 2',
86+
created_at: '2021-08-09T12:00:00Z',
87+
updated_at: '2021-08-09T12:00:00Z',
88+
id: 12346,
89+
schema: { type: 'object' },
90+
color: null,
91+
internal_tags_list: [],
92+
internal_tag_ids: [],
7393
}];
7494

7595
const result = await fetchComponents('12345', 'valid-token', 'eu');
@@ -94,6 +114,25 @@ describe('pull components actions', () => {
94114
expect(result).toEqual(mockResponse.components[0]);
95115
});
96116

117+
it('should choose the right component when multiple names match', async () => {
118+
const mockResponse = {
119+
components: [{
120+
name: 'name-2',
121+
display_name: 'Name 2',
122+
created_at: '2021-08-09T12:00:00Z',
123+
updated_at: '2021-08-09T12:00:00Z',
124+
id: 12346,
125+
schema: { type: 'object' },
126+
color: null,
127+
internal_tags_list: [],
128+
internal_tag_ids: [],
129+
}],
130+
};
131+
// searching for 'name-2' would match both 'component-name-2' and 'name-2'
132+
const result = await fetchComponent('12345', 'name-2', 'valid-token', 'eu');
133+
expect(result).toEqual(mockResponse.components[0]);
134+
});
135+
97136
it('should throw an masked error for invalid token', async () => {
98137
await expect(fetchComponents('12345', 'invalid-token', 'eu')).rejects.toThrow(
99138
expect.objectContaining({

src/commands/components/pull/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const fetchComponent = async (space: string, componentName: string, token
3434
Authorization: token,
3535
},
3636
});
37-
return response.components?.[0];
37+
return response.components?.find(c => c.name === componentName);
3838
}
3939
catch (error) {
4040
handleAPIError('pull_components', error as Error, `Failed to fetch component ${componentName}`);

src/commands/components/push/operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ export async function handleComponentGroups(
264264
: spaceData;
265265

266266
// First, process groups without parents
267-
// This conditional handles a strange scenario where group (folders) ids are equal to their parents
267+
// This conditional handles a strange scenario where group (folders) ids are equal to their parents
268268
const rootGroups = groupsToProcess.filter(group => (!group.parent_uuid || group.parent_uuid === group.uuid) && !group.parent_id);
269269
for (const group of rootGroups) {
270270
const spinner = new Spinner({

0 commit comments

Comments
 (0)