Skip to content

Commit 6198d3a

Browse files
test: add org resume scratch UT, refactor name to OrgResumeScratch
1 parent 7d41f5f commit 6198d3a

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

src/commands/org/resume/scratch.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { buildStatus } from '../../../shared/scratchOrgOutput.js';
2323
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
2424
const messages = Messages.loadMessages('@salesforce/plugin-org', 'resume_scratch');
2525

26-
export default class EnvResumeScratch extends SfCommand<ScratchCreateResponse> {
26+
export default class OrgResumeScratch extends SfCommand<ScratchCreateResponse> {
2727
public static readonly summary = messages.getMessage('summary');
2828
public static readonly description = messages.getMessage('description');
2929
public static readonly examples = messages.getMessages('examples');
@@ -46,7 +46,7 @@ export default class EnvResumeScratch extends SfCommand<ScratchCreateResponse> {
4646
};
4747

4848
public async run(): Promise<ScratchCreateResponse> {
49-
const { flags } = await this.parse(EnvResumeScratch);
49+
const { flags } = await this.parse(OrgResumeScratch);
5050
const cache = await ScratchOrgCache.create();
5151
const lifecycle = Lifecycle.getInstance();
5252

@@ -81,7 +81,6 @@ export default class EnvResumeScratch extends SfCommand<ScratchCreateResponse> {
8181
} else {
8282
throw SfError.wrap(e);
8383
}
84-
return {} as ScratchCreateResponse;
8584
}
8685
}
8786
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2023, 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 { config, expect } from 'chai';
8+
import sinon from 'sinon';
9+
import { stubMethod } from '@salesforce/ts-sinon';
10+
import { Messages, ScratchOrgCache, SfError } from '@salesforce/core';
11+
12+
import { stubSfCommandUx, stubUx } from '@salesforce/sf-plugins-core';
13+
import OrgResumeScratch from '../../../src/commands/org/resume/scratch.js';
14+
15+
config.truncateThreshold = 0;
16+
17+
describe('org:resume:scratch', () => {
18+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
19+
const messages = Messages.loadMessages('@salesforce/plugin-org', 'resume_scratch');
20+
const sandbox = sinon.createSandbox();
21+
beforeEach(() => {
22+
stubSfCommandUx(sandbox);
23+
stubUx(sandbox);
24+
});
25+
26+
afterEach(() => {
27+
sandbox.restore();
28+
});
29+
30+
it('will handle a cache miss gracefully', async () => {
31+
stubMethod(sandbox, ScratchOrgCache, 'create').resolves({
32+
get: () => {},
33+
keys: () => {},
34+
});
35+
36+
try {
37+
await OrgResumeScratch.run(['--job-id', '2SRFOOFOOFOOFOOFOO']);
38+
expect(false, 'ResumeSandbox should have thrown sandboxCreateNotComplete');
39+
} catch (err: unknown) {
40+
const error = err as SfError;
41+
expect(error.message).to.equal('The ScratchOrgInfoId 2SRFOOFOOFOOFOOFOO was not found in the cache.');
42+
expect(error.name).to.equal('CacheMissError');
43+
}
44+
});
45+
46+
it('will handle a cache miss gracefully and change message when other keys exist', async () => {
47+
stubMethod(sandbox, ScratchOrgCache, 'create').resolves({
48+
get: () => {},
49+
keys: () => ['abc', '123'],
50+
});
51+
52+
try {
53+
await OrgResumeScratch.run(['--job-id', '2SRFOOFOOFOOFOOFOO']);
54+
expect(false, 'ResumeSandbox should have thrown sandboxCreateNotComplete');
55+
} catch (err: unknown) {
56+
const error = err as SfError;
57+
expect(error.message).to.equal(messages.getMessage('error.jobIdMismatch', ['2SRFOOFOOFOOFOOFOO']));
58+
expect(error.name).to.equal('JobIdMismatchError');
59+
}
60+
});
61+
});

0 commit comments

Comments
 (0)