Skip to content

Commit 6a8a702

Browse files
committed
including new custom objects section
1 parent d1eb39c commit 6a8a702

File tree

5 files changed

+66
-10
lines changed

5 files changed

+66
-10
lines changed

src/core/changelog/__test__/generating-change-log.spec.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UnparsedApexBundle } from '../../shared/types';
1+
import { UnparsedApexBundle, UnparsedCustomObjectBundle } from '../../shared/types';
22
import { ChangeLogPageData, generateChangeLog } from '../generate-change-log';
33
import { assertEither } from '../../test-helpers/assert-either';
44
import { isSkip } from '../../shared/utils';
@@ -13,7 +13,19 @@ const config = {
1313
skipIfNoChanges: false,
1414
};
1515

16-
// TODO: new integration tests here
16+
export function customObjectGenerator(
17+
config: { deploymentStatus: string; visibility: string } = { deploymentStatus: 'Deployed', visibility: 'Public' },
18+
) {
19+
return `
20+
<?xml version="1.0" encoding="UTF-8"?>
21+
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
22+
<deploymentStatus>${config.deploymentStatus}</deploymentStatus>
23+
<description>test object for testing</description>
24+
<label>MyTestObject</label>
25+
<pluralLabel>MyFirstObjects</pluralLabel>
26+
<visibility>${config.visibility}</visibility>
27+
</CustomObject>`;
28+
}
1729

1830
describe('when generating a changelog', () => {
1931
it('should not skip when skipIfNoChanges, even if there are no changes', async () => {
@@ -185,6 +197,21 @@ describe('when generating a changelog', () => {
185197
});
186198
});
187199

200+
describe('that include new custom objects', () => {
201+
it('should include a section for new custom objects', async () => {
202+
const newObjectSource = customObjectGenerator();
203+
204+
const oldBundle: UnparsedCustomObjectBundle[] = [];
205+
const newBundle: UnparsedCustomObjectBundle[] = [
206+
{ type: 'customobject', name: 'MyTestObject', content: newObjectSource, filePath: 'MyTestObject.object' },
207+
];
208+
209+
const result = await generateChangeLog(oldBundle, newBundle, config)();
210+
211+
assertEither(result, (data) => expect((data as ChangeLogPageData).content).toContain('## New Custom Objects'));
212+
});
213+
});
214+
188215
describe('that includes new types out of scope', () => {
189216
it('should not include them', async () => {
190217
const newClassSource = 'class Test {}';

src/core/changelog/__test__/processing-changelog.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CustomFieldMetadataBuilder {
1717
return {
1818
type: 'Text',
1919
type_name: 'customfield',
20-
label: 'My Field',
20+
label: 'MyField',
2121
name: 'MyField',
2222
description: null,
2323
parentName: 'MyObject',
@@ -173,7 +173,7 @@ describe('when generating a changelog', () => {
173173
typeName: oldObject.name,
174174
modifications: [
175175
{
176-
__typename: 'LabelChanged',
176+
__typename: 'CustomObjectLabelChanged',
177177
name: 'NewLabel',
178178
},
179179
],
@@ -224,7 +224,6 @@ describe('when generating a changelog', () => {
224224
},
225225
]);
226226
});
227-
// [] - Lists changed field labels
228227
});
229228

230229
describe('with enum code', () => {

src/core/changelog/process-changelog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type ModificationTypes =
1818
| 'RemovedProperty'
1919
| 'NewField'
2020
| 'RemovedField'
21-
| 'LabelChanged';
21+
| 'CustomObjectLabelChanged';
2222

2323
export type MemberModificationType = {
2424
__typename: ModificationTypes;
@@ -114,7 +114,7 @@ function getModifiedCustomObjectLabels(typesInBoth: TypeInBoth<CustomObjectMetad
114114
.filter(({ oldType, newType }) => oldType.label.toLowerCase() !== newType.label.toLowerCase())
115115
.map(({ newType }) => ({
116116
typeName: newType.name,
117-
modifications: [{ __typename: 'LabelChanged', name: newType.label }],
117+
modifications: [{ __typename: 'CustomObjectLabelChanged', name: newType.label }],
118118
}));
119119
}
120120

src/core/changelog/renderable-changelog.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type NewTypeRenderable = {
99
description?: RenderableContent[];
1010
};
1111

12-
type NewTypeSection<T extends 'class' | 'interface' | 'enum'> = {
12+
type NewTypeSection<T extends 'class' | 'interface' | 'enum' | 'customobject'> = {
1313
__type: T;
1414
heading: string;
1515
description: string;
@@ -39,19 +39,25 @@ export type RenderableChangelog = {
3939
newEnums: NewTypeSection<'enum'> | null;
4040
removedTypes: RemovedTypeSection | null;
4141
newOrModifiedMembers: NewOrModifiedMembersSection | null;
42+
newCustomObjects: NewTypeSection<'customobject'> | null;
43+
// todo: removed custom objects
44+
// todo: changed custom objects
4245
};
4346

4447
export function convertToRenderableChangelog(
4548
changelog: Changelog,
4649
newManifest: (Type | CustomObjectMetadata)[],
4750
): RenderableChangelog {
48-
const allNewTypes = changelog.newApexTypes.map(
51+
const allNewTypes = [...changelog.newApexTypes, ...changelog.newCustomObjects].map(
4952
(newType) => newManifest.find((type) => type.name.toLowerCase() === newType.toLowerCase())!,
5053
);
5154

5255
const newClasses = allNewTypes.filter((type): type is ClassMirror => type.type_name === 'class');
5356
const newInterfaces = allNewTypes.filter((type): type is InterfaceMirror => type.type_name === 'interface');
5457
const newEnums = allNewTypes.filter((type): type is EnumMirror => type.type_name === 'enum');
58+
const newCustomObjects = allNewTypes.filter(
59+
(type): type is CustomObjectMetadata => type.type_name === 'customobject',
60+
);
5561

5662
return {
5763
newClasses:
@@ -93,6 +99,18 @@ export function convertToRenderableChangelog(
9399
modifications: changelog.newOrModifiedApexMembers.map(toRenderableModification),
94100
}
95101
: null,
102+
newCustomObjects:
103+
newCustomObjects.length > 0
104+
? {
105+
__type: 'customobject',
106+
heading: 'New Custom Objects',
107+
description: 'These custom objects are new.',
108+
types: newCustomObjects.map((type) => ({
109+
name: type.name,
110+
description: type.description ? [type.description] : undefined,
111+
})),
112+
}
113+
: null,
96114
};
97115
}
98116

@@ -137,7 +155,7 @@ function toRenderableModificationDescription(memberModificationType: MemberModif
137155
return `New Type: ${memberModificationType.name}`;
138156
case 'RemovedType':
139157
return `Removed Type: ${memberModificationType.name}`;
140-
case 'LabelChanged':
158+
case 'CustomObjectLabelChanged':
141159
return `Label Changed to ${memberModificationType.name}`;
142160
}
143161
}

src/core/changelog/templates/changelog-template.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ export const changelogTemplate = `
3737
{{/each}}
3838
{{/if}}
3939
40+
{{#if newCustomObjects}}
41+
## {{newCustomObjects.heading}}
42+
43+
{{newCustomObjects.description}}
44+
45+
{{#each newCustomObjects.types}}
46+
### {{this.name}}
47+
48+
{{{renderContent this.description}}}
49+
{{/each}}
50+
{{/if}}
51+
4052
{{#if removedTypes}}
4153
## Removed Types
4254

0 commit comments

Comments
 (0)