Skip to content

Commit 4250e94

Browse files
committed
Uts
1 parent fa32f6d commit 4250e94

File tree

3 files changed

+69
-8
lines changed

3 files changed

+69
-8
lines changed

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

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ function apexTypeFromRawString(raw: string): Type {
1313
}
1414

1515
class CustomFieldMetadataBuilder {
16+
name: string = 'MyField';
17+
18+
withName(name: string): CustomFieldMetadataBuilder {
19+
this.name = name;
20+
return this;
21+
}
22+
1623
build(): CustomFieldMetadata {
1724
return {
1825
type: 'Text',
1926
type_name: 'customfield',
2027
label: 'MyField',
21-
name: 'MyField',
28+
name: this.name,
2229
description: null,
2330
parentName: 'MyObject',
2431
};
@@ -29,11 +36,6 @@ class CustomObjectMetadataBuilder {
2936
label: string = 'MyObject';
3037
fields: CustomFieldMetadata[] = [];
3138

32-
withLabel(label: string): CustomObjectMetadataBuilder {
33-
this.label = label;
34-
return this;
35-
}
36-
3739
withField(field: CustomFieldMetadata): CustomObjectMetadataBuilder {
3840
this.fields.push(field);
3941
return this;
@@ -570,4 +572,65 @@ describe('when generating a changelog', () => {
570572
]);
571573
});
572574
});
575+
576+
describe('with custom field code', () => {
577+
it('does not list fields that are the same in both versions', () => {
578+
// A field that is the same in both versions is defined as one
579+
// with both the same name and the same parent
580+
581+
const oldField = new CustomFieldMetadataBuilder().build();
582+
const newField = new CustomFieldMetadataBuilder().build();
583+
584+
const oldManifest = { types: [oldField] };
585+
const newManifest = { types: [newField] };
586+
587+
const changeLog = processChangelog(oldManifest, newManifest);
588+
589+
expect(changeLog.customObjectModifications).toEqual([]);
590+
});
591+
592+
it('lists new fields of a custom object', () => {
593+
const oldField = new CustomFieldMetadataBuilder().build();
594+
const newField = new CustomFieldMetadataBuilder().withName('NewField').build();
595+
596+
const oldManifest = { types: [oldField] };
597+
const newManifest = { types: [oldField, newField] };
598+
599+
const changeLog = processChangelog(oldManifest, newManifest);
600+
601+
expect(changeLog.customObjectModifications).toEqual([
602+
{
603+
typeName: newField.parentName,
604+
modifications: [
605+
{
606+
__typename: 'NewField',
607+
name: newField.name,
608+
},
609+
],
610+
},
611+
]);
612+
});
613+
614+
it('lists removed fields of a custom object', () => {
615+
const oldField = new CustomFieldMetadataBuilder().withName('OldField').build();
616+
const unchangedField = new CustomFieldMetadataBuilder().build();
617+
618+
const oldManifest = { types: [unchangedField, oldField] };
619+
const newManifest = { types: [unchangedField] };
620+
621+
const changeLog = processChangelog(oldManifest, newManifest);
622+
623+
expect(changeLog.customObjectModifications).toEqual([
624+
{
625+
typeName: oldField.parentName,
626+
modifications: [
627+
{
628+
__typename: 'RemovedField',
629+
name: oldField.name,
630+
},
631+
],
632+
},
633+
]);
634+
});
635+
});
573636
});

src/core/changelog/generate-change-log.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ function reflect(bundles: UnparsedSourceBundle[], config: Omit<UserDefinedChange
7272
);
7373
}
7474

75-
// TODO: UTs
7675
function toManifests({ oldVersion, newVersion }: { oldVersion: ParsedFile[]; newVersion: ParsedFile[] }) {
7776
function parsedFilesToManifest(parsedFiles: ParsedFile[]): VersionManifest {
7877
return {

src/core/changelog/process-changelog.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ function getCustomObjectModifications(oldVersion: VersionManifest, newVersion: V
109109
);
110110
}
111111

112-
// TODO: UTs
113112
function getNewOrModifiedExtensionFields(
114113
oldVersion: VersionManifest,
115114
newVersion: VersionManifest,

0 commit comments

Comments
 (0)