Skip to content

Commit 43cace6

Browse files
committed
UT refactoring
1 parent c42fae2 commit 43cace6

File tree

4 files changed

+33
-79
lines changed

4 files changed

+33
-79
lines changed

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

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import {
2-
UnparsedApexBundle,
3-
UnparsedCustomFieldBundle,
4-
UnparsedCustomObjectBundle,
5-
UnparsedSourceBundle,
6-
} from '../../shared/types';
1+
import { UnparsedApexBundle, UnparsedCustomObjectBundle, UnparsedSourceBundle } from '../../shared/types';
72
import { ChangeLogPageData, generateChangeLog } from '../generate-change-log';
83
import { assertEither } from '../../test-helpers/assert-either';
94
import { isSkip } from '../../shared/utils';
10-
import { customObjectGenerator } from '../../test-helpers/test-data-builders';
5+
import { customObjectGenerator, unparsedFieldBundleFromRawString } from '../../test-helpers/test-data-builders';
116

127
const config = {
138
fileName: 'changelog',
@@ -19,32 +14,6 @@ const config = {
1914
skipIfNoChanges: false,
2015
};
2116

22-
export const customField = `
23-
<?xml version="1.0" encoding="UTF-8"?>
24-
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
25-
<fullName>PhotoUrl__c</fullName>
26-
<externalId>false</externalId>
27-
<label>PhotoUrl</label>
28-
<required>false</required>
29-
<trackFeedHistory>false</trackFeedHistory>
30-
<type>Url</type>
31-
<description>A URL that points to a photo</description>
32-
</CustomField>`;
33-
34-
function unparsedFieldBundleFromRawString(meta: {
35-
rawContent: string;
36-
filePath: string;
37-
parentName: string;
38-
}): UnparsedCustomFieldBundle {
39-
return {
40-
type: 'customfield',
41-
name: 'TestField__c',
42-
filePath: meta.filePath,
43-
content: meta.rawContent,
44-
parentName: meta.parentName,
45-
};
46-
}
47-
4817
describe('when generating a changelog', () => {
4918
it('should not skip when skipIfNoChanges, even if there are no changes', async () => {
5019
const result = await generateChangeLog([], [], { ...config })();
@@ -369,7 +338,6 @@ describe('when generating a changelog', () => {
369338
const newBundle: UnparsedSourceBundle[] = [
370339
{ type: 'customobject', name: 'MyTestObject', content: newObjectSource, filePath: 'MyTestObject.object' },
371340
unparsedFieldBundleFromRawString({
372-
rawContent: customField,
373341
filePath: 'MyTestObject__c.field-meta.xml',
374342
parentName: 'MyTestObject',
375343
}),
@@ -392,7 +360,6 @@ describe('when generating a changelog', () => {
392360
const newBundle: UnparsedSourceBundle[] = [
393361
{ type: 'customobject', name: 'MyTestObject', content: newObjectSource, filePath: 'MyTestObject.object' },
394362
unparsedFieldBundleFromRawString({
395-
rawContent: customField,
396363
filePath: 'MyTestObject__c.field-meta.xml',
397364
parentName: 'MyTestObject',
398365
}),
@@ -410,7 +377,6 @@ describe('when generating a changelog', () => {
410377
const oldBundle: UnparsedSourceBundle[] = [
411378
{ type: 'customobject', name: 'MyTestObject', content: oldObjectSource, filePath: 'MyTestObject.object' },
412379
unparsedFieldBundleFromRawString({
413-
rawContent: customField,
414380
filePath: 'MyTestObject__c.field-meta.xml',
415381
parentName: 'MyTestObject',
416382
}),

src/core/markdown/__test__/generating-custom-object-docs.spec.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { extendExpect } from './expect-extensions';
2-
import {
3-
customField,
4-
generateDocs,
5-
unparsedFieldBundleFromRawString,
6-
unparsedObjectBundleFromRawString,
7-
} from './test-helpers';
2+
import { generateDocs, unparsedObjectBundleFromRawString } from './test-helpers';
83
import { assertEither } from '../../test-helpers/assert-either';
9-
import { customObjectGenerator } from '../../test-helpers/test-data-builders';
4+
import { customObjectGenerator, unparsedFieldBundleFromRawString } from '../../test-helpers/test-data-builders';
105

116
describe('Generates Custom Object documentation', () => {
127
beforeAll(() => {
@@ -54,7 +49,6 @@ describe('Generates Custom Object documentation', () => {
5449
});
5550

5651
const customFieldBundle = unparsedFieldBundleFromRawString({
57-
rawContent: customField,
5852
filePath: 'src/object/TestField__c.field-meta.xml',
5953
parentName: 'TestObject__c',
6054
});
@@ -82,7 +76,6 @@ describe('Generates Custom Object documentation', () => {
8276
});
8377

8478
const customFieldBundle = unparsedFieldBundleFromRawString({
85-
rawContent: customField,
8679
filePath: 'src/object/TestField__c.field-meta.xml',
8780
parentName: 'TestObject__c',
8881
});
@@ -99,7 +92,6 @@ describe('Generates Custom Object documentation', () => {
9992
});
10093

10194
const customFieldBundle = unparsedFieldBundleFromRawString({
102-
rawContent: customField,
10395
filePath: 'src/object/TestField__c.field-meta.xml',
10496
parentName: 'TestObject__c',
10597
});
@@ -116,7 +108,6 @@ describe('Generates Custom Object documentation', () => {
116108
});
117109

118110
const customFieldBundle = unparsedFieldBundleFromRawString({
119-
rawContent: customField,
120111
filePath: 'src/object/TestField__c.field-meta.xml',
121112
parentName: 'TestObject__c',
122113
});
Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
UnparsedApexBundle,
3-
UnparsedCustomFieldBundle,
4-
UnparsedCustomObjectBundle,
5-
UnparsedSourceBundle,
6-
} from '../../shared/types';
1+
import { UnparsedApexBundle, UnparsedCustomObjectBundle, UnparsedSourceBundle } from '../../shared/types';
72
import { generateDocs as gen, MarkdownGeneratorConfig } from '../generate-docs';
83
import { referenceGuideTemplate } from '../templates/reference-guide';
94

@@ -29,20 +24,6 @@ export function unparsedObjectBundleFromRawString(meta: {
2924
};
3025
}
3126

32-
export function unparsedFieldBundleFromRawString(meta: {
33-
rawContent: string;
34-
filePath: string;
35-
parentName: string;
36-
}): UnparsedCustomFieldBundle {
37-
return {
38-
type: 'customfield',
39-
name: 'TestField__c',
40-
filePath: meta.filePath,
41-
content: meta.rawContent,
42-
parentName: meta.parentName,
43-
};
44-
}
45-
4627
export function generateDocs(apexBundles: UnparsedSourceBundle[], config?: Partial<MarkdownGeneratorConfig>) {
4728
return gen(apexBundles, {
4829
targetDir: 'target',
@@ -58,15 +39,3 @@ export function generateDocs(apexBundles: UnparsedSourceBundle[], config?: Parti
5839
...config,
5940
});
6041
}
61-
62-
export const customField = `
63-
<?xml version="1.0" encoding="UTF-8"?>
64-
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
65-
<fullName>PhotoUrl__c</fullName>
66-
<externalId>false</externalId>
67-
<label>PhotoUrl</label>
68-
<required>false</required>
69-
<trackFeedHistory>false</trackFeedHistory>
70-
<type>Url</type>
71-
<description>A URL that points to a photo</description>
72-
</CustomField>`;

src/core/test-helpers/test-data-builders.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { UnparsedCustomFieldBundle } from '../shared/types';
2+
13
export function customObjectGenerator(
24
config: { deploymentStatus: string; visibility: string } = { deploymentStatus: 'Deployed', visibility: 'Public' },
35
) {
@@ -11,3 +13,29 @@ export function customObjectGenerator(
1113
<visibility>${config.visibility}</visibility>
1214
</CustomObject>`;
1315
}
16+
17+
export const customField = `
18+
<?xml version="1.0" encoding="UTF-8"?>
19+
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
20+
<fullName>PhotoUrl__c</fullName>
21+
<externalId>false</externalId>
22+
<label>PhotoUrl</label>
23+
<required>false</required>
24+
<trackFeedHistory>false</trackFeedHistory>
25+
<type>Url</type>
26+
<description>A URL that points to a photo</description>
27+
</CustomField>`;
28+
29+
export function unparsedFieldBundleFromRawString(meta: {
30+
rawContent?: string;
31+
filePath: string;
32+
parentName: string;
33+
}): UnparsedCustomFieldBundle {
34+
return {
35+
type: 'customfield',
36+
name: 'TestField__c',
37+
filePath: meta.filePath,
38+
content: meta.rawContent ?? customField,
39+
parentName: meta.parentName,
40+
};
41+
}

0 commit comments

Comments
 (0)