11import { processChangelog } from '../process-changelog' ;
22import { reflect , Type } from '@cparra/apex-reflection' ;
3- import { CustomObjectMetadata } from '../../reflection/sobject/reflect-custom-object-sources' ;
4- import { CustomFieldMetadata } from '../../reflection/sobject/reflect-custom-field-source' ;
3+ import CustomFieldMetadataBuilder from './helpers/custom-field-metadata-builder' ;
4+ import CustomObjectMetadataBuilder from './helpers/custom-object-metadata-builder' ;
5+ import CustomMetadataMetadataBuilder from './helpers/custom-metadata-metadata-builder' ;
56
67function apexTypeFromRawString ( raw : string ) : Type {
78 const result = reflect ( raw ) ;
@@ -12,56 +13,6 @@ function apexTypeFromRawString(raw: string): Type {
1213 return result . typeMirror ! ;
1314}
1415
15- class CustomFieldMetadataBuilder {
16- name : string = 'MyField' ;
17- description : string | null = null ;
18-
19- withName ( name : string ) : CustomFieldMetadataBuilder {
20- this . name = name ;
21- return this ;
22- }
23-
24- withDescription ( testDescription : string ) {
25- this . description = testDescription ;
26- return this ;
27- }
28-
29- build ( ) : CustomFieldMetadata {
30- return {
31- type : 'Text' ,
32- type_name : 'customfield' ,
33- label : 'MyField' ,
34- name : this . name ,
35- description : this . description ,
36- parentName : 'MyObject' ,
37- required : false ,
38- } ;
39- }
40- }
41-
42- class CustomObjectMetadataBuilder {
43- label : string = 'MyObject' ;
44- fields : CustomFieldMetadata [ ] = [ ] ;
45-
46- withField ( field : CustomFieldMetadata ) : CustomObjectMetadataBuilder {
47- this . fields . push ( field ) ;
48- return this ;
49- }
50-
51- build ( ) : CustomObjectMetadata {
52- return {
53- type_name : 'customobject' ,
54- deploymentStatus : 'Deployed' ,
55- visibility : 'Public' ,
56- label : this . label ,
57- name : 'MyObject' ,
58- description : null ,
59- fields : this . fields ,
60- metadataRecords : [ ] ,
61- } ;
62- }
63- }
64-
6516describe ( 'when generating a changelog' , ( ) => {
6617 it ( 'has no new types when both the old and new versions are empty' , ( ) => {
6718 const oldVersion = { types : [ ] } ;
@@ -669,4 +620,71 @@ describe('when generating a changelog', () => {
669620 ] ) ;
670621 } ) ;
671622 } ) ;
623+
624+ describe ( 'with custom metadata records' , ( ) => {
625+ it ( 'does not list custom metadata records that are the same in both versions' , ( ) => {
626+ // The record uniqueness is determined by its api name.
627+
628+ const oldCustomMetadata = new CustomMetadataMetadataBuilder ( ) . build ( ) ;
629+ const newCustomMetadata = new CustomMetadataMetadataBuilder ( ) . build ( ) ;
630+
631+ const oldManifest = { types : [ oldCustomMetadata ] } ;
632+ const newManifest = { types : [ newCustomMetadata ] } ;
633+
634+ const changeLog = processChangelog ( oldManifest , newManifest ) ;
635+
636+ expect ( changeLog . customObjectModifications ) . toEqual ( [ ] ) ;
637+ } ) ;
638+
639+ it ( 'lists new records of a custom object' , ( ) => {
640+ const oldObject = new CustomObjectMetadataBuilder ( )
641+ . withMetadataRecord ( new CustomMetadataMetadataBuilder ( ) . build ( ) )
642+ . build ( ) ;
643+ const newObject = new CustomObjectMetadataBuilder ( )
644+ . withMetadataRecord ( new CustomMetadataMetadataBuilder ( ) . build ( ) )
645+ . withMetadataRecord ( new CustomMetadataMetadataBuilder ( ) . withName ( 'NewField__c' ) . build ( ) )
646+ . build ( ) ;
647+
648+ const oldManifest = { types : [ oldObject ] } ;
649+ const newManifest = { types : [ newObject ] } ;
650+
651+ const changeLog = processChangelog ( oldManifest , newManifest ) ;
652+
653+ expect ( changeLog . customObjectModifications ) . toEqual ( [
654+ {
655+ typeName : newObject . name ,
656+ modifications : [
657+ {
658+ __typename : 'NewCustomMetadataRecord' ,
659+ name : 'NewField__c' ,
660+ } ,
661+ ] ,
662+ } ,
663+ ] ) ;
664+ } ) ;
665+
666+ it ( 'lists removed records of a custom object' , ( ) => {
667+ const oldObject = new CustomObjectMetadataBuilder ( )
668+ . withMetadataRecord ( new CustomMetadataMetadataBuilder ( ) . withName ( 'OldField__c' ) . build ( ) )
669+ . build ( ) ;
670+ const newObject = new CustomObjectMetadataBuilder ( ) . build ( ) ;
671+
672+ const oldManifest = { types : [ oldObject ] } ;
673+ const newManifest = { types : [ newObject ] } ;
674+
675+ const changeLog = processChangelog ( oldManifest , newManifest ) ;
676+
677+ expect ( changeLog . customObjectModifications ) . toEqual ( [
678+ {
679+ typeName : oldObject . name ,
680+ modifications : [
681+ {
682+ __typename : 'RemovedCustomMetadataRecord' ,
683+ name : 'OldField__c' ,
684+ } ,
685+ ] ,
686+ } ,
687+ ] ) ;
688+ } ) ;
689+ } ) ;
672690} ) ;
0 commit comments