|
7 | 7 | import fs from 'node:fs'; |
8 | 8 | import path from 'node:path'; |
9 | 9 |
|
| 10 | +import { parseJsonMap } from '@salesforce/kit'; |
10 | 11 | import { execCmd, genUniqueString, TestSession } from '@salesforce/cli-plugins-testkit'; |
11 | 12 | import { assert, expect } from 'chai'; |
12 | 13 | import { AuthFields, Messages, Global, StateAggregator } from '@salesforce/core'; |
@@ -64,6 +65,96 @@ describe('env create scratch NUTs', () => { |
64 | 65 | describe('successes', () => { |
65 | 66 | const keys = ['username', 'orgId', 'scratchOrgInfo', 'authFields', 'warnings']; |
66 | 67 |
|
| 68 | + it('creates an org with capitalized record types if no config var is set', async () => { |
| 69 | + const scratchDefJson = parseJsonMap( |
| 70 | + await fs.promises.readFile(path.join(session.project.dir, 'config', 'project-scratch-def.json'), 'utf8') |
| 71 | + ); |
| 72 | + scratchDefJson.objectSettings = { |
| 73 | + case: { |
| 74 | + defaultRecordType: 'Svc_Technical_Support', |
| 75 | + }, |
| 76 | + }; |
| 77 | + |
| 78 | + // NOTE: remove this once it starts capitalizing record types by default. |
| 79 | + // we are unsetting it here to ensure the warning from sfdx-core is emitted. |
| 80 | + await execCmd('config unset org-capitalize-record-types', { |
| 81 | + async: true, |
| 82 | + cli: 'sf', |
| 83 | + ensureExitCode: 0, |
| 84 | + }); |
| 85 | + |
| 86 | + await fs.promises.writeFile( |
| 87 | + path.join(session.project.dir, 'config', 'project-scratch-def-1.json'), |
| 88 | + JSON.stringify(scratchDefJson), |
| 89 | + 'utf-8' |
| 90 | + ); |
| 91 | + |
| 92 | + const jsonOutput = execCmd<ScratchCreateResponse>( |
| 93 | + 'org create scratch -d -f config/project-scratch-def-1.json -a dreamhouse --duration-days 1 --json', |
| 94 | + { |
| 95 | + ensureExitCode: 0, |
| 96 | + } |
| 97 | + ).jsonOutput; |
| 98 | + |
| 99 | + const noConfigVarWarning = |
| 100 | + 'Record types defined in the scratch org definition file will stop being capitalized by default in a future release.\nSet the `org-capitalize-record-types` config var to `true` to enforce capitalization.'; |
| 101 | + |
| 102 | + expect(jsonOutput?.warnings[0] === noConfigVarWarning); |
| 103 | + |
| 104 | + const username = jsonOutput?.result.username; |
| 105 | + |
| 106 | + const recordTypes = execCmd<{ recordTypeInfos: Array<{ name: string }> }>( |
| 107 | + `sobject describe --sobject Case --target-org ${username}`, |
| 108 | + { |
| 109 | + cli: 'sf', |
| 110 | + ensureExitCode: 0, |
| 111 | + } |
| 112 | + ).jsonOutput?.result.recordTypeInfos; |
| 113 | + |
| 114 | + expect(recordTypes?.find((rt) => rt.name === 'Svc_Technical_Support')); |
| 115 | + }); |
| 116 | + it('creates an org without capitalized record types', async () => { |
| 117 | + const scratchDefJson = parseJsonMap( |
| 118 | + await fs.promises.readFile(path.join(session.project.dir, 'config', 'project-scratch-def.json'), 'utf8') |
| 119 | + ); |
| 120 | + scratchDefJson.objectSettings = { |
| 121 | + case: { |
| 122 | + defaultRecordType: 'Svc_Technical_Support', |
| 123 | + }, |
| 124 | + }; |
| 125 | + |
| 126 | + // NOTE: remove this once it starts capitalizing record types by default. |
| 127 | + await execCmd('config set org-capitalize-record-types=false', { |
| 128 | + async: true, |
| 129 | + cli: 'sf', |
| 130 | + ensureExitCode: 0, |
| 131 | + }); |
| 132 | + |
| 133 | + await fs.promises.writeFile( |
| 134 | + path.join(session.project.dir, 'config', 'project-scratch-def-1.json'), |
| 135 | + JSON.stringify(scratchDefJson), |
| 136 | + 'utf-8' |
| 137 | + ); |
| 138 | + |
| 139 | + const jsonOutput = execCmd<ScratchCreateResponse>( |
| 140 | + 'org create scratch -d -f config/project-scratch-def-1.json -a dreamhouse --duration-days 1 --json', |
| 141 | + { |
| 142 | + ensureExitCode: 0, |
| 143 | + } |
| 144 | + ).jsonOutput; |
| 145 | + |
| 146 | + const username = jsonOutput?.result.username; |
| 147 | + |
| 148 | + const recordTypes = execCmd<{ recordTypeInfos: Array<{ name: string }> }>( |
| 149 | + `sobject describe --sobject Case --target-org ${username}`, |
| 150 | + { |
| 151 | + cli: 'sf', |
| 152 | + ensureExitCode: 0, |
| 153 | + } |
| 154 | + ).jsonOutput?.result.recordTypeInfos; |
| 155 | + |
| 156 | + expect(recordTypes?.find((rt) => rt.name === 'svc_Technical_Support')); |
| 157 | + }); |
67 | 158 | it('creates an org from edition flag only and sets tracking to true by default', async () => { |
68 | 159 | const resp = execCmd<ScratchCreateResponse>('env:create:scratch --edition developer --json --wait 60', { |
69 | 160 | ensureExitCode: 0, |
|
0 commit comments