Skip to content

Commit

Permalink
test: prove that junction objects work for upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jun 4, 2024
1 parent f885550 commit 87951a1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 7 deletions.
70 changes: 70 additions & 0 deletions test/commands/data/tree/dataTreeJunction.ts
Original file line number Diff line number Diff line change
@@ -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<ImportResult[]>(
`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<ImportResult[]>(
`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);
});
});
7 changes: 0 additions & 7 deletions test/test-files/data-project/data/junction/Account.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{
"records": [
{
"attributes": {
"type": "Account",
"referenceId": "AccountRef1"
},
"Name": "Sample Account for Entitlements"
},
{
"attributes": {
"type": "Account",
Expand Down

0 comments on commit 87951a1

Please sign in to comment.