Skip to content

Commit 9d3f4f5

Browse files
fix: add package1:beta:version:create:get command, UTs, placeholder NUT
1 parent 7389687 commit 9d3f4f5

File tree

6 files changed

+154
-25
lines changed

6 files changed

+154
-25
lines changed

messages/default.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,8 @@ Stopped waiting for package upload to finish. Wait time exceeded. waitTimeInMinu
897897

898898
# package1VersionCreateCommandUploadFailure
899899

900-
Package upload failed. ${os.EOL}%s
901-
902-
# package1VersionCreateCommandUploadFailureDefault
903-
904-
Package version creation failed with unknown error
900+
Package upload failed.
901+
%s
905902

906903
# package1VersionCreateHumanSuccess
907904

messages/package1_version_create_get.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22

33
retrieve the status of a package version creation request
44

5-
# cliDescriptionLong
6-
7-
Retrieves the status of a package version creation request.
8-
9-
# help
5+
# examples
106

117
Examples:
12-
$ sfdx force:package:version:create:report -i 08c...
13-
$ sfdx force:package:version:create:report -i 08c... -v [email protected]
8+
$ sfdx force:package1:version:create:get -i 0HD...
9+
$ sfdx force:package1:version:create:get -i 0HD... -u [email protected]
1410

1511
# requestId
1612

src/commands/force/package1/beta/version/create/get.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8+
import * as os from 'os';
89
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
910
import { Messages } from '@salesforce/core';
11+
import { PackagingSObjects, package1VersionCreateGet } from '@salesforce/packaging';
1012

1113
Messages.importMessagesDirectory(__dirname);
1214
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package1_version_create_get');
15+
const defaultMessages = Messages.loadMessages('@salesforce/plugin-packaging', 'default');
1316

1417
export class Package1VersionCreateGetCommand extends SfdxCommand {
1518
public static readonly description = messages.getMessage('cliDescription');
16-
public static readonly longDescription = messages.getMessage('cliDescriptionLong');
17-
public static readonly help = messages.getMessage('help');
18-
public static readonly;
19+
public static readonly examples = messages.getMessage('examples').split(os.EOL);
1920
public static readonly requiresUsername = true;
2021
public static readonly flagsConfig: FlagsConfig = {
2122
requestid: flags.id({
@@ -26,8 +27,21 @@ export class Package1VersionCreateGetCommand extends SfdxCommand {
2627
}),
2728
};
2829

29-
public async run(): Promise<unknown> {
30-
process.exitCode = 1;
31-
return Promise.resolve('Not yet implemented');
30+
public async run(): Promise<PackagingSObjects.PackageUploadRequest> {
31+
const result = await package1VersionCreateGet(this.org.getConnection(), this.flags.requestid);
32+
33+
if (result.Status === 'ERROR') {
34+
// toolbelt was accessing request.Errors.errors, I'm unsure about this type, but was unable to reproduce an error
35+
// in the wild, and decided to trust how it was working
36+
const errors = (result.Errors as unknown as { errors: Error[] })?.errors?.map((e) => e.message).join('\n');
37+
throw defaultMessages.createError('package1VersionCreateCommandUploadFailure', [
38+
errors ?? 'Package version creation failed with unknown error',
39+
]);
40+
} else {
41+
const arg = result.Status === 'SUCCESS' ? [result.MetadataPackageVersionId] : [result.Id, this.org.getUsername()];
42+
this.ux.log(messages.getMessage(result.Status, arg));
43+
}
44+
45+
return result;
3246
}
3347
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright (c) 2020, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
import { Org } from '@salesforce/core';
8+
import { testSetup } from '@salesforce/core/lib/testSetup';
9+
import { fromStub, stubInterface, stubMethod } from '@salesforce/ts-sinon';
10+
import { Config } from '@oclif/core';
11+
import { assert, expect } from 'chai';
12+
import { Package1VersionCreateGetCommand } from '../../../../src/commands/force/package1/beta/version/create/get';
13+
14+
const $$ = testSetup();
15+
const oclifConfigStub = fromStub(stubInterface<Config>($$.SANDBOX));
16+
let uxStub: sinon.SinonStub;
17+
18+
class TestCommand extends Package1VersionCreateGetCommand {
19+
public async runIt() {
20+
await this.init();
21+
22+
uxStub = stubMethod($$.SANDBOX, this.ux, 'log');
23+
return this.run();
24+
}
25+
public setOrg(org: Org) {
26+
this.org = org;
27+
}
28+
}
29+
30+
const runCmd = async (params: string[], result: string, errors?: { errors: Error[] }) => {
31+
const cmd = new TestCommand(params, oclifConfigStub);
32+
33+
stubMethod($$.SANDBOX, cmd, 'assignOrg').callsFake(() => {
34+
const orgStub = fromStub(
35+
stubInterface<Org>($$.SANDBOX, {
36+
getUsername: () => '[email protected]',
37+
getConnection: () => {
38+
return {
39+
tooling: {
40+
sobject: () => {
41+
return {
42+
retrieve: () => {
43+
return Promise.resolve({
44+
Status: result,
45+
MetadataPackageVersionId: '04t4p000002BavTXXX',
46+
Errors: errors,
47+
});
48+
},
49+
};
50+
},
51+
},
52+
};
53+
},
54+
})
55+
);
56+
cmd.setOrg(orgStub);
57+
});
58+
return cmd.runIt();
59+
};
60+
61+
describe('force:package1:version:create:get', () => {
62+
afterEach(() => {
63+
$$.SANDBOX.restore();
64+
});
65+
it('should print SUCCESS status correctly', async () => {
66+
const result = await runCmd(['--requestid', '0HD4p000000blSkXXX'], 'SUCCESS');
67+
expect(result.Status).to.equal('SUCCESS');
68+
expect(uxStub.callCount).to.equal(1);
69+
expect(uxStub.firstCall.args[0]).to.equal('Successfully uploaded package [04t4p000002BavTXXX]');
70+
});
71+
72+
it('should print IN_PROGRESS status correctly', async () => {
73+
const result = await runCmd(['--requestid', '0HD4p000000blSkXXX'], 'IN_PROGRESS');
74+
expect(result.Status).to.equal('IN_PROGRESS');
75+
expect(uxStub.callCount).to.equal(1);
76+
expect(uxStub.firstCall.args[0]).to.equal(
77+
'PackageUploadRequest is still InProgress. You can query the status using\n' +
78+
'sfdx force:package1:version:create:get -i undefined -u [email protected]'
79+
);
80+
});
81+
82+
it('should print QUEUED status correctly', async () => {
83+
const result = await runCmd(['--requestid', '0HD4p000000blSkXXX'], 'QUEUED');
84+
expect(result.Status).to.equal('QUEUED');
85+
expect(uxStub.callCount).to.equal(1);
86+
expect(uxStub.firstCall.args[0]).to.equal(
87+
'PackageUploadRequest has been enqueued. You can query the status using\n' +
88+
'sfdx force:package1:version:create:get -i undefined -u [email protected]'
89+
);
90+
});
91+
92+
it('should print ERROR status correctly, undefined errors', async () => {
93+
try {
94+
await runCmd(['--requestid', '0HD4p000000blSkXXX'], 'ERROR');
95+
assert.fail('the above should throw an erorr, from the ERROR status');
96+
} catch (e) {
97+
expect((e as Error).message).to.equal(
98+
'Package upload failed. \nPackage version creation failed with unknown error'
99+
);
100+
}
101+
});
102+
103+
it('should print ERROR status correctly, multiple errors', async () => {
104+
try {
105+
await runCmd(['--requestid', '0HD4p000000blSkXXX'], 'ERROR', { errors: [new Error('message1')] });
106+
assert.fail('the above should throw an erorr, from the ERROR status');
107+
} catch (e) {
108+
expect((e as Error).message).to.equal('Package upload failed. \nmessage1');
109+
}
110+
});
111+
112+
it('should print ERROR status correctly, multiple errors (2+)', async () => {
113+
try {
114+
await runCmd(['--requestid', '0HD4p000000blSkXXX'], 'ERROR', {
115+
errors: [new Error('message1'), new Error('message2')],
116+
});
117+
assert.fail('the above should throw an erorr, from the ERROR status');
118+
} catch (e) {
119+
expect((e as Error).message).to.equal('Package upload failed. \nmessage1\nmessage2');
120+
}
121+
});
122+
});

tsconfig.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
"extends": "@salesforce/dev-config/tsconfig",
33
"compilerOptions": {
44
"outDir": "lib",
5-
"rootDir": "src"
5+
"rootDir": "src",
6+
"baseUrl": ".",
7+
"paths": {
8+
"jsforce": ["node_modules/jsforce"],
9+
"@salesforce/core": ["node_modules/@salesforce/core"]
10+
}
611
},
712
"include": ["./src/**/*.ts"]
813
}

yarn.lock

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,12 +1245,7 @@
12451245
resolved "https://registry.yarnpkg.com/@salesforce/prettier-config/-/prettier-config-0.0.2.tgz#ded39bf7cb75238edc9db6dd093649111350f8bc"
12461246
integrity sha512-KExM355BLbxCW6siGBV7oUOotXvvVp0tAWERgzUkM2FcMb9fWrjwXDrIHc8V0UdDlA3UXtFltDWgN+Yqi+BA/g==
12471247

1248-
"@salesforce/schemas@^1.0.1", "@salesforce/schemas@^1.1.0":
1249-
version "1.1.3"
1250-
resolved "https://registry.yarnpkg.com/@salesforce/schemas/-/schemas-1.1.3.tgz#fce83f55c7557d47b9c814d5d02978ad734300b3"
1251-
integrity sha512-XWohlOT2oQDqAJH00OXS3f2MGjkwZ6pr4emnnkHSQbg7UdGW0rvGpEnRKqBbDUfZ4K5YKSo9Gj216ZtaP3JLXg==
1252-
1253-
"@salesforce/schemas@^1.2.0":
1248+
"@salesforce/schemas@^1.0.1", "@salesforce/schemas@^1.1.0", "@salesforce/schemas@^1.2.0":
12541249
version "1.2.0"
12551250
resolved "https://registry.yarnpkg.com/@salesforce/schemas/-/schemas-1.2.0.tgz#3c7ed492e3ee5d9d9fb24a32b5c574893f6648db"
12561251
integrity sha512-76oYf/9Rsn6Yl+awrTQvLaQuRDNX7F3X9ksRiw53OCJdydIF05buX6XLzN0WDWpkCg/asw+lZMuAzbDVS0tBmg==

0 commit comments

Comments
 (0)