|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, 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 } from '@oclif/core'; |
| 8 | +import { TestContext, MockTestOrgData } from '@salesforce/core/testSetup'; |
| 9 | +import * as sinon from 'sinon'; |
| 10 | +import { expect } from 'chai'; |
| 11 | +import { BundleCreateOptions, PackageBundle } from '@salesforce/packaging'; |
| 12 | +import { stubSfCommandUx } from '@salesforce/sf-plugins-core'; |
| 13 | +import { Connection, SfProject } from '@salesforce/core'; |
| 14 | +import { PackageBundlesCreate } from '../../../src/commands/package/bundles/create.js'; |
| 15 | + |
| 16 | +describe('force:bundle:create - tests', () => { |
| 17 | + const $$ = new TestContext(); |
| 18 | + const testOrg = new MockTestOrgData(); |
| 19 | + let sfCommandStubs: ReturnType<typeof stubSfCommandUx>; |
| 20 | + let createStub: sinon.SinonStub<[Connection, SfProject, BundleCreateOptions], Promise<{ Id: string }>>; |
| 21 | + const config = new Config({ root: import.meta.url }); |
| 22 | + |
| 23 | + beforeEach(async () => { |
| 24 | + await $$.stubAuths(testOrg); |
| 25 | + await config.load(); |
| 26 | + sfCommandStubs = stubSfCommandUx($$.SANDBOX); |
| 27 | + |
| 28 | + createStub = $$.SANDBOX.stub(PackageBundle, 'create'); |
| 29 | + }); |
| 30 | + |
| 31 | + afterEach(() => { |
| 32 | + $$.restore(); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should create a bundle', async () => { |
| 36 | + const bundleName = 'dummyPackageId'; |
| 37 | + const cmd = new PackageBundlesCreate(['-v', testOrg.username, '--name', bundleName], config); |
| 38 | + |
| 39 | + createStub.resolves({ Id: 'test-id' }); |
| 40 | + |
| 41 | + await cmd.run(); |
| 42 | + |
| 43 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access |
| 44 | + expect(sfCommandStubs.table.calledOnce).to.be.true; |
| 45 | + }); |
| 46 | + |
| 47 | + it('should throw error when name flag is missing', async () => { |
| 48 | + const cmd = new PackageBundlesCreate(['-v', testOrg.username], config); |
| 49 | + |
| 50 | + createStub.resolves({ Id: 'test-id' }); |
| 51 | + |
| 52 | + try { |
| 53 | + await cmd.run(); |
| 54 | + expect.fail('Expected error was not thrown'); |
| 55 | + } catch (error) { |
| 56 | + expect((error as Error).message).to.include('Missing required flag name'); |
| 57 | + } |
| 58 | + }); |
| 59 | + |
| 60 | + it('should throw error when test org flag is missing', async () => { |
| 61 | + const cmd = new PackageBundlesCreate(['--name', 'dummyPackageId'], config); |
| 62 | + |
| 63 | + createStub.resolves({ Id: 'test-id' }); |
| 64 | + |
| 65 | + try { |
| 66 | + await cmd.run(); |
| 67 | + expect.fail('Expected error was not thrown'); |
| 68 | + } catch (error) { |
| 69 | + expect((error as Error).message).to.include('No default dev hub found'); |
| 70 | + } |
| 71 | + }); |
| 72 | +}); |
0 commit comments