|
| 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 { expect } from 'chai'; |
| 10 | +import { PackageBundleVersion } from '@salesforce/packaging'; |
| 11 | +import { stubSfCommandUx } from '@salesforce/sf-plugins-core'; |
| 12 | +import sinon from 'sinon'; |
| 13 | +import { PackageBundleVersionListCommand } from '../../../src/commands/package/bundle/version/list.js'; |
| 14 | +describe('package:bundle:version:list - tests', () => { |
| 15 | + const $$ = new TestContext(); |
| 16 | + const testOrg = new MockTestOrgData(); |
| 17 | + let sfCommandStubs: ReturnType<typeof stubSfCommandUx>; |
| 18 | + let listStub: sinon.SinonStub; |
| 19 | + const config = new Config({ root: import.meta.url }); |
| 20 | + |
| 21 | + beforeEach(async () => { |
| 22 | + await $$.stubAuths(testOrg); |
| 23 | + await config.load(); |
| 24 | + sfCommandStubs = stubSfCommandUx($$.SANDBOX); |
| 25 | + |
| 26 | + listStub = $$.SANDBOX.stub(PackageBundleVersion, 'list'); |
| 27 | + }); |
| 28 | + |
| 29 | + afterEach(() => { |
| 30 | + $$.restore(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should list a bundle', async () => { |
| 34 | + const cmd = new PackageBundleVersionListCommand(['-v', testOrg.username], config); |
| 35 | + |
| 36 | + listStub.resolves([ |
| 37 | + { |
| 38 | + Id: 'test-version-id', |
| 39 | + PackageBundle: { |
| 40 | + Id: 'test-bundle-id', |
| 41 | + BundleName: 'test-bundle', |
| 42 | + Description: undefined, |
| 43 | + IsDeleted: false, |
| 44 | + CreatedDate: '2025-01-01T00:00:00.000Z', |
| 45 | + CreatedById: 'test-user-id', |
| 46 | + LastModifiedDate: '2025-01-01T00:00:00.000Z', |
| 47 | + LastModifiedById: 'test-user-id', |
| 48 | + SystemModstamp: '2025-01-01T00:00:00.000Z', |
| 49 | + }, |
| 50 | + VersionName: 'test-version', |
| 51 | + MajorVersion: '1', |
| 52 | + MinorVersion: '0', |
| 53 | + CreatedDate: '2025-01-01T00:00:00.000Z', |
| 54 | + CreatedById: 'test-user-id', |
| 55 | + LastModifiedDate: '2025-01-01T00:00:00.000Z', |
| 56 | + LastModifiedById: 'test-user-id', |
| 57 | + Ancestor: null, |
| 58 | + IsReleased: false, |
| 59 | + }, |
| 60 | + ]); |
| 61 | + |
| 62 | + await cmd.run(); |
| 63 | + |
| 64 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access |
| 65 | + expect(sfCommandStubs.table.calledOnce).to.be.true; |
| 66 | + }); |
| 67 | + |
| 68 | + it('should throw error when test org flag is missing', async () => { |
| 69 | + const cmd = new PackageBundleVersionListCommand([], config); |
| 70 | + |
| 71 | + listStub.resolves([ |
| 72 | + { |
| 73 | + Id: 'test-version-id', |
| 74 | + PackageBundle: { |
| 75 | + Id: 'test-bundle-id', |
| 76 | + BundleName: 'test-bundle', |
| 77 | + Description: undefined, |
| 78 | + IsDeleted: false, |
| 79 | + CreatedDate: '2025-01-01T00:00:00.000Z', |
| 80 | + CreatedById: 'test-user-id', |
| 81 | + LastModifiedDate: '2025-01-01T00:00:00.000Z', |
| 82 | + LastModifiedById: 'test-user-id', |
| 83 | + SystemModstamp: '2025-01-01T00:00:00.000Z', |
| 84 | + }, |
| 85 | + VersionName: 'test-version', |
| 86 | + MajorVersion: '1', |
| 87 | + MinorVersion: '0', |
| 88 | + CreatedDate: '2025-01-01T00:00:00.000Z', |
| 89 | + CreatedById: 'test-user-id', |
| 90 | + LastModifiedDate: '2025-01-01T00:00:00.000Z', |
| 91 | + LastModifiedById: 'test-user-id', |
| 92 | + Ancestor: null, |
| 93 | + IsReleased: false, |
| 94 | + }, |
| 95 | + ]); |
| 96 | + |
| 97 | + try { |
| 98 | + await cmd.run(); |
| 99 | + expect.fail('Expected error was not thrown'); |
| 100 | + } catch (error) { |
| 101 | + expect((error as Error).message).to.include('No default dev hub found'); |
| 102 | + } |
| 103 | + }); |
| 104 | +}); |
0 commit comments