Skip to content

Commit

Permalink
feat: modify fileResponse for not found in org on Deletes (#472)
Browse files Browse the repository at this point in the history
* feat: modify fileResponse for not found in org on Deletes

* test: verify for matchingContentType

* refactor: pr feedback (jsdoc, named type for object)

* refactor: handle various destructive filenames

Co-authored-by: Steve Hetzel <[email protected]>
  • Loading branch information
mshanemc and shetzel committed Nov 2, 2021
1 parent e3a10d3 commit 9d258fc
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 5 deletions.
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ All notable changes to this project will be documented in this file. See [standa

### [5.1.1](https://github.com/forcedotcom/source-deploy-retrieve/compare/v5.1.0...v5.1.1) (2021-10-28)


### Bug Fixes

* ensure component.content is always assigned ([#485](https://github.com/forcedotcom/source-deploy-retrieve/issues/485)) ([d77f475](https://github.com/forcedotcom/source-deploy-retrieve/commit/d77f47502634206ac59181362b7f17da82ed01e7))
- ensure component.content is always assigned ([#485](https://github.com/forcedotcom/source-deploy-retrieve/issues/485)) ([d77f475](https://github.com/forcedotcom/source-deploy-retrieve/commit/d77f47502634206ac59181362b7f17da82ed01e7))

## [5.1.0](https://github.com/forcedotcom/source-deploy-retrieve/compare/v5.0.3...v5.1.0) (2021-10-28)


### Features

* construct virtual tree from array of paths ([#480](https://github.com/forcedotcom/source-deploy-retrieve/issues/480)) ([99954dc](https://github.com/forcedotcom/source-deploy-retrieve/commit/99954dc731d078e99283eed940b98ee63688a024))
- construct virtual tree from array of paths ([#480](https://github.com/forcedotcom/source-deploy-retrieve/issues/480)) ([99954dc](https://github.com/forcedotcom/source-deploy-retrieve/commit/99954dc731d078e99283eed940b98ee63688a024))

### [5.0.3](https://github.com/forcedotcom/source-deploy-retrieve/compare/v5.0.2...v5.0.3) (2021-10-28)

Expand Down
37 changes: 36 additions & 1 deletion src/client/metadataApiDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class DeployResult implements MetadataTransferResult {
}
}

return fileResponses;
return fileResponses.concat(this.deleteNotFoundToFileResponses(messages));
}

private createResponses(component: SourceComponent, messages: DeployMessage[]): FileResponse[] {
Expand Down Expand Up @@ -146,6 +146,41 @@ export class DeployResult implements MetadataTransferResult {
return messageMap;
}

/**
* If a components fails to delete because it doesn't exist in the org, you get a message like
* key: 'ApexClass#destructiveChanges.xml'
* value:[{
* fullName: 'destructiveChanges.xml',
* fileName: 'destructiveChanges.xml',
* componentType: 'ApexClass',
* problem: 'No ApexClass named: test1 found',
* problemType: 'Warning'
* }]
*/
private deleteNotFoundToFileResponses(messageMap: Map<string, DeployMessage[]>): FileResponse[] {
const fileResponses: FileResponse[] = [];
messageMap.forEach((messages, key) => {
if (key.includes('destructiveChanges') && key.endsWith('.xml')) {
messages.forEach((message) => {
if (message.problemType === 'Warning' && message.problem.startsWith(`No ${message.componentType} named: `)) {
const fullName = message.problem.replace(`No ${message.componentType} named: `, '').replace(' found', '');
this.components
.getComponentFilenamesByNameAndType({ fullName, type: message.componentType })
.forEach((fileName) => {
fileResponses.push({
fullName,
type: message.componentType,
filePath: fileName,
state: ComponentStatus.Deleted,
});
});
}
});
}
});
return fileResponses;
}

/**
* Fix any issues with the deploy message returned by the api.
* TODO: remove cases if fixes are made in the api.
Expand Down
22 changes: 22 additions & 0 deletions src/collections/componentSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
TreeContainer,
} from '../resolve';
import { MetadataType, RegistryAccess } from '../registry';
import { MetadataMember } from '../resolve/types';
import {
DestructiveChangesType,
FromManifestOptions,
Expand Down Expand Up @@ -477,6 +478,27 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
return false;
}

/**
* For a fullName and type, this returns the filenames the matching component, or an empty array if the component is not present
*
* @param param Object with fullName and type properties
* @returns string[]
*/
public getComponentFilenamesByNameAndType({ fullName, type }: MetadataMember): string[] {
const key = this.simpleKey({ fullName, type });
const componentMap = this.components.get(key);
if (!componentMap) {
return [];
}
const output = new Set<string>();
componentMap.forEach((component) => {
[...component.walkContent(), component.content, component.xml]
.filter(Boolean)
.map((filename) => output.add(filename));
});
return Array.from(output);
}

public *[Symbol.iterator](): Iterator<MetadataComponent> {
for (const [key, sourceComponents] of this.components.entries()) {
if (sourceComponents.size === 0) {
Expand Down
38 changes: 38 additions & 0 deletions test/client/metadataApiDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
DECOMPOSED_CHILD_COMPONENT_2,
DECOMPOSED_COMPONENT,
} from '../mock/registry/type-constants/decomposedConstants';
import { COMPONENT } from '../mock/registry/type-constants/matchingContentFileConstants';
import { MissingJobIdError } from '../../src/errors';

const env = createSandbox();
Expand Down Expand Up @@ -714,6 +715,43 @@ describe('MetadataApiDeploy', () => {

expect(responses).to.deep.equal(expected);
});

it('should report "Deleted" when no component in org', () => {
const component = COMPONENT;
const deployedSet = new ComponentSet([component]);
const apiStatus: Partial<MetadataApiDeployStatus> = {
details: {
componentFailures: {
changed: 'false',
created: 'false',
deleted: 'false',
fullName: 'destructiveChanges.xml',
componentType: component.type.name,
problem: `No ${component.type.name} named: ${component.fullName} found`,
problemType: 'Warning',
} as DeployMessage,
},
};
const result = new DeployResult(apiStatus as MetadataApiDeployStatus, deployedSet);

const responses = result.getFileResponses();
const expected: FileResponse[] = [
{
fullName: component.fullName,
type: component.type.name,
state: ComponentStatus.Deleted,
filePath: component.content,
},
{
fullName: component.fullName,
type: component.type.name,
state: ComponentStatus.Deleted,
filePath: component.xml,
},
];

expect(responses).to.deep.equal(expected);
});
});
});

Expand Down

0 comments on commit 9d258fc

Please sign in to comment.