From 92ab6a6183814d432d56f41be485b2d937518122 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Wed, 11 Oct 2023 11:38:12 -0600 Subject: [PATCH] fix: remove duplicates from file responses --- src/client/metadataApiDeploy.ts | 3 +- test/client/metadataApiDeploy.test.ts | 57 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/client/metadataApiDeploy.ts b/src/client/metadataApiDeploy.ts index ceb42e8e50..bafb3352ed 100644 --- a/src/client/metadataApiDeploy.ts +++ b/src/client/metadataApiDeploy.ts @@ -86,7 +86,8 @@ export class DeployResult implements MetadataTransferResult { ); } } - return this.fileResponses; + // removes duplicates from the file responses by parsing the object into a string, used as the key of the map + return [...new Map(this.fileResponses.map((v) => [JSON.stringify(v), v])).values()]; } private createResponses(component: SourceComponent, responseMessages: DeployMessage[]): FileResponse[] { diff --git a/test/client/metadataApiDeploy.test.ts b/test/client/metadataApiDeploy.test.ts index fd44ced1f4..7b719b70ce 100644 --- a/test/client/metadataApiDeploy.test.ts +++ b/test/client/metadataApiDeploy.test.ts @@ -819,6 +819,63 @@ describe('MetadataApiDeploy', () => { expect(responses).to.deep.equal(expected); }); + it('should not report duplicates component', () => { + const component = matchingContentFile.COMPONENT; + const deployedSet = new ComponentSet([component]); + const { fullName, type, content } = component; + const problem = 'something went wrong'; + const problemType = 'Error'; + const apiStatus: Partial = { + details: { + componentFailures: [ + { + changed: 'false', + created: 'false', + deleted: 'false', + success: 'false', + lineNumber: '3', + columnNumber: '5', + problem, + problemType, + fullName, + fileName: component.content, + componentType: type.name, + } as DeployMessage, + { + changed: 'false', + created: 'false', + deleted: 'false', + success: 'false', + lineNumber: '3', + columnNumber: '5', + problem, + problemType, + fullName, + fileName: component.content, + componentType: type.name, + } as DeployMessage, + ], + }, + }; + const result = new DeployResult(apiStatus as MetadataApiDeployStatus, deployedSet); + + const responses = result.getFileResponses(); + const expected: FileResponse[] = [ + { + fullName, + type: type.name, + state: ComponentStatus.Failed, + filePath: content, + error: `${problem} (3:5)`, + lineNumber: 3, + columnNumber: 5, + problemType, + }, + ]; + + expect(responses).to.deep.equal(expected); + }); + it('should report children of deployed component', () => { const component = DECOMPOSED_COMPONENT; const deployedSet = new ComponentSet([component]);