-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpackageVersionCreate.test.ts
More file actions
249 lines (233 loc) · 10.1 KB
/
Copy pathpackageVersionCreate.test.ts
File metadata and controls
249 lines (233 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import os from 'node:os';
import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup';
import { Config } from '@oclif/core';
import { assert, expect } from 'chai';
import { PackageVersion, PackageVersionCreateRequestResult, PackagingSObjects } from '@salesforce/packaging';
import sinon from 'sinon';
import { SfCommand } from '@salesforce/sf-plugins-core';
import { env } from '@salesforce/kit';
import { PackageVersionCreateCommand } from '../../../src/commands/package/version/create.js';
import Package2VersionStatus = PackagingSObjects.Package2VersionStatus;
const pkgVersionCreateErrorResult: PackageVersionCreateRequestResult = {
Id: '08c3i000000fylXXXX',
Status: Package2VersionStatus.error,
Package2Id: '0Ho3i000000TNHXXXX',
Package2VersionId: '',
SubscriberPackageVersionId: '',
Tag: '',
Branch: '',
Error: [
'PropertyController: Invalid type: Schema.Property__c',
'SampleDataController: Invalid type: Schema.Property__c',
'SampleDataController: Invalid type: Schema.Broker__c',
],
CreatedDate: '2022-11-03 09:21',
HasMetadataRemoved: null,
CreatedBy: '0053i000001ZIyXXXX',
Package2Name: null,
HasPassedCodeCoverageCheck: null,
CodeCoverage: null,
VersionNumber: null,
ConvertedFromVersionId: null,
TotalNumberOfMetadataFiles: null,
TotalSizeOfMetadataFiles: null,
};
const pkgVersionCreateSuccessResult: PackageVersionCreateRequestResult = {
Id: '08c3i000000fylgAAA',
Status: Package2VersionStatus.success,
Package2Id: '0Ho3i000000TNHYCA4',
Package2VersionId: '05i3i000000fxw1AAA',
SubscriberPackageVersionId: '04t3i000002eya2AAA',
Tag: '',
Branch: '',
Error: [],
CreatedDate: '2022-11-03 09:46',
HasMetadataRemoved: false,
CreatedBy: '0053i000001ZIyGAAW',
Package2Name: null,
HasPassedCodeCoverageCheck: null,
CodeCoverage: null,
VersionNumber: null,
ConvertedFromVersionId: null,
TotalNumberOfMetadataFiles: null,
TotalSizeOfMetadataFiles: null,
};
const pkgVersionCreateSuccessResultExceedsFileCount: PackageVersionCreateRequestResult = {
Id: '08c3i000000fylgAAA',
Status: Package2VersionStatus.success,
Package2Id: '0Ho3i000000TNHYCA4',
Package2VersionId: '05i3i000000fxw1AAA',
SubscriberPackageVersionId: '04t3i000002eya2AAA',
Tag: '',
Branch: '',
Error: [],
CreatedDate: '2022-11-03 09:46',
HasMetadataRemoved: false,
CreatedBy: '0053i000001ZIyGAAW',
Package2Name: null,
HasPassedCodeCoverageCheck: null,
CodeCoverage: null,
VersionNumber: null,
ConvertedFromVersionId: null,
TotalNumberOfMetadataFiles: 8000,
TotalSizeOfMetadataFiles: 500 * 1024 * 1024,
};
describe('package:version:create - tests', () => {
const $$ = new TestContext();
const testOrg = new MockTestOrgData();
let createStub = $$.SANDBOX.stub(PackageVersion, 'create');
const config = new Config({ root: import.meta.url });
// stubs
let logStub: sinon.SinonStub;
let warnStub: sinon.SinonStub;
const stubSpinner = (cmd: PackageVersionCreateCommand) => {
$$.SANDBOX.stub(cmd.spinner, 'start');
$$.SANDBOX.stub(cmd.spinner, 'stop');
};
before(async () => {
await $$.stubAuths(testOrg);
await config.load();
});
beforeEach(async () => {
logStub = $$.SANDBOX.stub(SfCommand.prototype, 'log');
warnStub = $$.SANDBOX.stub(SfCommand.prototype, 'warn');
});
afterEach(() => {
$$.restore();
});
describe('package:version:create', () => {
it('should create a new package version', async () => {
createStub.resolves(pkgVersionCreateSuccessResult);
const envSpy = $$.SANDBOX.spy(env, 'setBoolean').withArgs('SF_APPLY_REPLACEMENTS_ON_CONVERT', true);
const cmd = new PackageVersionCreateCommand(['-p', '05i3i000000Gmj6XXX', '-v', 'test@hub.org', '-x'], config);
stubSpinner(cmd);
const res = await cmd.run();
expect(envSpy.calledOnce).to.equal(true);
expect(res).to.deep.equal({
Branch: '',
CreatedBy: '0053i000001ZIyGAAW',
CreatedDate: '2022-11-03 09:46',
Error: [],
HasMetadataRemoved: false,
Id: '08c3i000000fylgAAA',
Package2Id: '0Ho3i000000TNHYCA4',
Package2VersionId: '05i3i000000fxw1AAA',
Status: 'Success',
SubscriberPackageVersionId: '04t3i000002eya2AAA',
Tag: '',
Package2Name: null,
HasPassedCodeCoverageCheck: null,
CodeCoverage: null,
VersionNumber: null,
ConvertedFromVersionId: null,
TotalNumberOfMetadataFiles: null,
TotalSizeOfMetadataFiles: null,
});
expect(warnStub.callCount).to.equal(0);
expect(logStub.callCount).to.equal(1);
expect(logStub.args[0]).to.deep.equal([
`Successfully created the package version [08c3i000000fylgAAA]. Subscriber Package Version Id: 04t3i000002eya2AAA${os.EOL}Package Installation URL: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t3i000002eya2AAA${os.EOL}As an alternative, you can use the "sf package install" command.`,
]);
});
it('should create a new package version with async validation', async () => {
createStub = $$.SANDBOX.stub(PackageVersion, 'create');
createStub.resolves(pkgVersionCreateSuccessResult);
const envSpy = $$.SANDBOX.spy(env, 'setBoolean').withArgs('SF_APPLY_REPLACEMENTS_ON_CONVERT', true);
const cmd = new PackageVersionCreateCommand(
['-p', '05i3i000000Gmj6XXX', '-v', 'test@hub.org', '-x', '--async-validation'],
config
);
stubSpinner(cmd);
const res = await cmd.run();
expect(envSpy.calledOnce).to.equal(true);
expect(res).to.deep.equal({
Branch: '',
CreatedBy: '0053i000001ZIyGAAW',
CreatedDate: '2022-11-03 09:46',
Error: [],
HasMetadataRemoved: false,
Id: '08c3i000000fylgAAA',
Package2Id: '0Ho3i000000TNHYCA4',
Package2VersionId: '05i3i000000fxw1AAA',
Status: 'Success',
SubscriberPackageVersionId: '04t3i000002eya2AAA',
Tag: '',
Package2Name: null,
HasPassedCodeCoverageCheck: null,
CodeCoverage: null,
VersionNumber: null,
ConvertedFromVersionId: null,
TotalNumberOfMetadataFiles: null,
TotalSizeOfMetadataFiles: null,
});
expect(warnStub.callCount).to.equal(0);
expect(logStub.callCount).to.equal(1);
expect(logStub.args[0]).to.deep.equal([
`Successfully created the package version [08c3i000000fylgAAA]. Subscriber Package Version Id: 04t3i000002eya2AAA${os.EOL}Package Installation URL: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t3i000002eya2AAA${os.EOL}As an alternative, you can use the "sf package install" command.`,
]);
});
it('should create a new package version with total file-count exceeding threshold', async () => {
createStub = $$.SANDBOX.stub(PackageVersion, 'create');
createStub.resolves(pkgVersionCreateSuccessResultExceedsFileCount);
const envSpy = $$.SANDBOX.spy(env, 'setBoolean').withArgs('SF_APPLY_REPLACEMENTS_ON_CONVERT', true);
const cmd = new PackageVersionCreateCommand(
['-p', '05i3i000000Gmj6XXX', '-v', 'test@hub.org', '-x', '--async-validation'],
config
);
stubSpinner(cmd);
const res = await cmd.run();
expect(envSpy.calledOnce).to.equal(true);
expect(res).to.deep.equal({
Branch: '',
CreatedBy: '0053i000001ZIyGAAW',
CreatedDate: '2022-11-03 09:46',
Error: [],
HasMetadataRemoved: false,
Id: '08c3i000000fylgAAA',
Package2Id: '0Ho3i000000TNHYCA4',
Package2VersionId: '05i3i000000fxw1AAA',
Status: 'Success',
SubscriberPackageVersionId: '04t3i000002eya2AAA',
Tag: '',
Package2Name: null,
HasPassedCodeCoverageCheck: null,
CodeCoverage: null,
VersionNumber: null,
ConvertedFromVersionId: null,
TotalNumberOfMetadataFiles: 8000,
TotalSizeOfMetadataFiles: 500 * 1024 * 1024,
});
expect(warnStub.callCount).to.equal(2);
expect(warnStub.args[0]).to.deep.equal([
'This package contains more than 7000 metadata files. The maximum number of metadata files in a package is 10000. If you reach the file limit, you won’t be able to create new package versions. To confirm the exact file count for this package, run sf package version report and review the “# Metadata Files” column.',
]);
expect(warnStub.args[1]).to.deep.equal([
'The maximum size of all the metadata files size in a single package is 600 MB. The package version you’re creating exceeds 70% of the metadata file size limit. If you reach the file size limit, you won’t be able to create new package versions. To confirm the exact file size for this package, run "sf package version report" and review the “Metadata File Size” column.',
]);
expect(logStub.callCount).to.equal(1);
expect(logStub.args[0]).to.deep.equal([
`Successfully created the package version [08c3i000000fylgAAA]. Subscriber Package Version Id: 04t3i000002eya2AAA${os.EOL}Package Installation URL: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t3i000002eya2AAA${os.EOL}As an alternative, you can use the "sf package install" command.`,
]);
});
it('should report multiple errors', async () => {
createStub = $$.SANDBOX.stub(PackageVersion, 'create');
createStub.resolves(pkgVersionCreateErrorResult);
try {
const cmd = new PackageVersionCreateCommand(['-p', '05i3i000000Gmj6XXX', '-v', 'test@hub.org', '-x'], config);
stubSpinner(cmd);
await cmd.run();
assert.fail('the above should throw multiple errors');
} catch (e) {
expect((e as Error).message).to.equal(
`Multiple errors occurred: ${os.EOL}(1) PropertyController: Invalid type: Schema.Property__c${os.EOL}(2) SampleDataController: Invalid type: Schema.Property__c${os.EOL}(3) SampleDataController: Invalid type: Schema.Broker__c`
);
}
});
});
});