diff --git a/test/commands/data/tree/dataTreeJunction.ts b/test/commands/data/tree/dataTreeJunction.ts new file mode 100644 index 00000000..56193cad --- /dev/null +++ b/test/commands/data/tree/dataTreeJunction.ts @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2020, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import path from 'node:path'; +import { expect } from 'chai'; +import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; +import { ImportResult } from '../../../../src/api/data/tree/importTypes.js'; + +describe('data:tree commands', () => { + let testSession: TestSession; + + before(async () => { + testSession = await TestSession.create({ + scratchOrgs: [ + { + config: 'config/project-scratch-def.json', + setDefault: true, + }, + { + config: 'config/project-scratch-def.json', + setDefault: false, + alias: 'importOrg', + }, + ], + project: { sourceDir: path.join('test', 'test-files', 'data-project') }, + devhubAuthStrategy: 'AUTO', + }); + }); + + after(async () => { + await testSession?.clean(); + }); + + it('new tree can import junction objects', () => { + const importResult = execCmd( + `data:import:beta:tree --plan ${path.join( + 'data', + 'junction', + 'Account-AccountContactRelation-Contact-plan.json' + )} --json`, + { ensureExitCode: 0 } + ); + expect(importResult.jsonOutput?.result.length).to.equal(12); + }); + + it('import -> export -> import round trip should succeed', () => { + const query = + "select Id, Name, (Select Id, FirstName, LastName, (select AccountId, ContactId from AccountContactRoles) from Contacts), (select Id, ContactId, AccountId from AccountContactRelations where Account.Name != 'We Know Everybody') from Account where Name != 'Sample Account for Entitlements'"; + + execCmd(`data:export:beta:tree --query "${query}" --outputdir ${path.join('.', 'export_data')} --plan --json`, { + ensureExitCode: 0, + }); + + // Import data to the default org. + const importResult = execCmd( + `data:import:beta:tree --target-org importOrg --plan ${path.join( + '.', + 'export_data', + 'Account-AccountContactRelation-Contact-plan.json' + )} --json`, + { + ensureExitCode: 0, + } + ); + expect(importResult.jsonOutput?.result.length).to.equal(12); + }); +}); diff --git a/test/test-files/data-project/data/junction/Account.json b/test/test-files/data-project/data/junction/Account.json index 225dd7df..6493c5d9 100644 --- a/test/test-files/data-project/data/junction/Account.json +++ b/test/test-files/data-project/data/junction/Account.json @@ -1,12 +1,5 @@ { "records": [ - { - "attributes": { - "type": "Account", - "referenceId": "AccountRef1" - }, - "Name": "Sample Account for Entitlements" - }, { "attributes": { "type": "Account",