Skip to content

Commit

Permalink
Merge pull request #103 from vbihun/does-not-delete-external-alias-af…
Browse files Browse the repository at this point in the history
…ter-removing-compass-yaml

Does not delete external alias after removing compass yaml
  • Loading branch information
vbihun committed Apr 30, 2024
2 parents d986529 + 75335fb commit 6f5ac1d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mockAgg, mockUnlinkComponent } from '../../../__tests__/helpers/mock-ag

mockAgg();

import { ConfigFileActions } from '@atlassian/forge-graphql';
import { ConfigFileActions, UnLinkComponentInput } from '@atlassian/forge-graphql';
import { mocked } from 'jest-mock';
import { generatePushEvent } from '../../../__tests__/helpers/gitlab-helper';
import { handlePushEvent } from './handle-push-event';
Expand Down Expand Up @@ -37,6 +37,16 @@ describe('Gitlab push events', () => {
componentYaml: { id: 'test2' },
filePath: '/compass.yml',
deduplicationId: '1',
shouldRemoveExternalAlias: true,
},
];

const mockComponentsToUnlinkWithoutExternalAliasesToRemove = [
{
componentYaml: { id: 'test2' },
filePath: '/compass.yml',
deduplicationId: '1',
shouldRemoveExternalAlias: false,
},
];

Expand All @@ -55,6 +65,16 @@ describe('Gitlab push events', () => {
},
];

const mockUnlinkComponentDataWithoutExternalAliasesToRemove: UnLinkComponentInput[] = [
{
componentId: 'test2',
cloudId: MOCK_CLOUD_ID,
filePath: `/compass.yml`,
deduplicationId: '1',
additionalExternalAliasesToRemove: [],
},
];

beforeEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -172,4 +192,17 @@ describe('Gitlab push events', () => {
});
expect(removals).toBeCalledWith(mockUnlinkComponentData[0]);
});

it('does not delete externalAlias for the current component', async () => {
getNonDefaultBranchNameMock.mockResolvedValue(event.project.default_branch);
findConfigChanges.mockResolvedValue({
componentsToCreate: [],
componentsToUpdate: [],
componentsToUnlink: mockComponentsToUnlinkWithoutExternalAliasesToRemove,
});

await handlePushEvent(event, TEST_TOKEN, MOCK_CLOUD_ID);

expect(removals).toBeCalledWith(mockUnlinkComponentDataWithoutExternalAliasesToRemove[0]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export const handlePushEvent = async (event: PushEvent, groupToken: string, clou
filePath: componentToUnlink.filePath,
componentId: componentToUnlink.componentYaml.id,
deduplicationId: componentToUnlink.deduplicationId,
additionalExternalAliasesToRemove: [{ externalId: event.project.id.toString(), externalSource: EXTERNAL_SOURCE }],
additionalExternalAliasesToRemove: componentToUnlink.shouldRemoveExternalAlias
? [{ externalId: event.project.id.toString(), externalSource: EXTERNAL_SOURCE }]
: [],
}),
);
await Promise.all([...creates, ...updates, ...removals]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const handleModifiedFilesAndUpdateComponentChanges =

for (const { oldFile, newFile } of modifiedFiles) {
if (isFileIdentifierChanged(oldFile, newFile)) {
unlinks.push(oldFile);
unlinks.push({ ...oldFile, shouldRemoveExternalAlias: true });
creates.push(newFile);
} else {
updates.push(newFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ describe('findConfigAsCodeFileChanges', () => {
componentYaml: compassYamlBefore,
filePath: '/compass.yml',
deduplicationId: baseEvent.project.id.toString(),
shouldRemoveExternalAlias: true,
},
],
};
Expand Down Expand Up @@ -352,6 +353,7 @@ describe('findConfigAsCodeFileChanges', () => {
componentYaml: compassYamlBefore,
filePath: '/compass.yml',
deduplicationId: event.project.id.toString(),
shouldRemoveExternalAlias: true,
},
],
};
Expand Down Expand Up @@ -380,6 +382,7 @@ describe('findConfigAsCodeFileChanges', () => {
componentYaml: compassYamlBefore,
filePath: '/compass.yml',
deduplicationId: event.project.id.toString(),
shouldRemoveExternalAlias: true,
},
],
};
Expand Down Expand Up @@ -653,6 +656,7 @@ describe('findConfigAsCodeFileChanges', () => {
componentYaml: compassYamlBefore,
filePath: '/compass.yml',
deduplicationId: event.project.id.toString(),
shouldRemoveExternalAlias: true,
},
],
};
Expand Down Expand Up @@ -708,6 +712,7 @@ describe('findConfigAsCodeFileChanges', () => {
componentYaml: compassYamlBefore,
filePath: '/compass.yml',
deduplicationId: event.project.id.toString(),
shouldRemoveExternalAlias: true,
},
],
};
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export type ComponentUnlinkPayload = {
componentYaml: CompassYaml;
deduplicationId?: string;
filePath?: string;
shouldRemoveExternalAlias?: boolean;
};

type ModifiedFilePayload = {
Expand Down

0 comments on commit 6f5ac1d

Please sign in to comment.