|
5 | 5 | * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause |
6 | 6 | */ |
7 | 7 |
|
8 | | -describe('sourceCommand tests', () => {}); |
| 8 | +import { ComponentSet } from '@salesforce/source-deploy-retrieve'; |
| 9 | +import { asArray, asString } from '@salesforce/ts-types'; |
| 10 | +import { stubMethod } from '@salesforce/ts-sinon'; |
| 11 | +import { expect, $$ } from '@salesforce/command/lib/test'; |
| 12 | +import { fs } from '@salesforce/core'; |
| 13 | +import { SinonStub } from 'sinon'; |
| 14 | +import { FlagOptions, SourceCommand } from '../../../src/sourceCommand'; |
| 15 | + |
| 16 | +class sourceCommandTest extends SourceCommand { |
| 17 | + public async run() {} |
| 18 | + public async callCreateCopmonentSet(options: FlagOptions): Promise<ComponentSet> { |
| 19 | + return await this.createComponentSet(options); |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +describe('sourceCommand tests', () => { |
| 24 | + describe('createComponentSet tests', () => { |
| 25 | + const command = new sourceCommandTest([''], null); |
| 26 | + let fromSource: SinonStub; |
| 27 | + let fromManifest: SinonStub; |
| 28 | + |
| 29 | + beforeEach(() => { |
| 30 | + stubMethod($$.SANDBOX, fs, 'fileExistsSync').returns(true); |
| 31 | + fromSource = stubMethod($$.SANDBOX, ComponentSet, 'fromSource').returns([ |
| 32 | + { name: 'MyTest', type: { id: 'apexclass', name: 'ApexClass' }, xml: '', parent: undefined, content: '' }, |
| 33 | + ]); |
| 34 | + fromManifest = stubMethod($$.SANDBOX, ComponentSet, 'fromManifestFile').resolves([ |
| 35 | + { name: 'MyTest', type: { id: 'apexclass', name: 'ApexClass' }, xml: '', parent: undefined, content: '' }, |
| 36 | + ]); |
| 37 | + }); |
| 38 | + |
| 39 | + it('will create appropriate ComponentSet from path', async () => { |
| 40 | + try { |
| 41 | + await command.callCreateCopmonentSet({ |
| 42 | + sourcepath: asArray<string>(['force-app']), |
| 43 | + manifest: asString(''), |
| 44 | + metadata: asArray<string>([]), |
| 45 | + }); |
| 46 | + } catch (e) { |
| 47 | + // we can't stub everything needed to create a ComponentSet, so expect the constructor to throw |
| 48 | + // but we'll spy on everything and make sure it looks correct |
| 49 | + // we need lots of NUTs |
| 50 | + } |
| 51 | + expect(fromSource.callCount).to.equal(1); |
| 52 | + }); |
| 53 | + |
| 54 | + it('will create appropriate ComponentSet from multiple paths', async () => { |
| 55 | + try { |
| 56 | + await command.callCreateCopmonentSet({ |
| 57 | + sourcepath: asArray<string>(['force-app', 'my-app']), |
| 58 | + manifest: asString(''), |
| 59 | + metadata: asArray<string>([]), |
| 60 | + }); |
| 61 | + } catch (e) { |
| 62 | + // we can't stub everything needed to create a ComponentSet, so expect the constructor to throw |
| 63 | + // but we'll spy on everything and make sure it looks correct |
| 64 | + // we need lots of NUTs |
| 65 | + } |
| 66 | + expect(fromSource.callCount).to.equal(2); |
| 67 | + }); |
| 68 | + |
| 69 | + it('will create appropriate ComponentSet from packagenames', async () => { |
| 70 | + // TODO: Flush out once we can retrieve via packagenames |
| 71 | + }); |
| 72 | + |
| 73 | + it('will create appropriate ComponentSet from multiple packagenames', async () => { |
| 74 | + // TODO: Flush out once we can retrieve via packagenames |
| 75 | + }); |
| 76 | + |
| 77 | + it('will create appropriate ComponentSet from metadata (ApexClass)', async () => { |
| 78 | + // not sure how to stub ComponentSet constructor |
| 79 | + }); |
| 80 | + |
| 81 | + it('will create appropriate ComponentSet from metadata (ApexClass:MyClass)', async () => { |
| 82 | + // not sure how to stub ComponentSet constructor |
| 83 | + }); |
| 84 | + |
| 85 | + it('will create appropriate ComponentSet from metadata (ApexClass:MyClass,CustomObject,CustomField:MyField', async () => { |
| 86 | + // not sure how to stub ComponentSet constructor |
| 87 | + }); |
| 88 | + |
| 89 | + it('will create appropriate ComponentSet from manifest', async () => { |
| 90 | + try { |
| 91 | + await command.callCreateCopmonentSet({ |
| 92 | + sourcepath: asArray<string>([]), |
| 93 | + manifest: asString('manifest.xml'), |
| 94 | + metadata: asArray<string>(['']), |
| 95 | + }); |
| 96 | + } catch (e) { |
| 97 | + // we can't stub everything needed to create a ComponentSet, so expect the constructor to throw |
| 98 | + // but we'll spy on everything and make sure it looks correct |
| 99 | + // we need lots of NUTs |
| 100 | + } |
| 101 | + expect(fromManifest.callCount).to.equal(1); |
| 102 | + }); |
| 103 | + }); |
| 104 | +}); |
0 commit comments