|
| 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