generated from salesforcecli/lerna-template
-
Notifications
You must be signed in to change notification settings - Fork 12
/
record.test.ts
46 lines (41 loc) · 1.55 KB
/
record.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* 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 { resolve } from 'path';
import { Config } from '@oclif/core';
import { expect } from 'chai';
import { TestContext, MockTestOrgData } from '@salesforce/core/lib/testSetup';
import { AnyJson, ensureJsonMap, ensureString } from '@salesforce/ts-types';
import { SaveResult } from 'jsforce';
import Create from '../../../../src/commands/data/create/record';
const sObjectId = '0011100001zhhyUAAQ';
describe('force:data:record:create', () => {
const $$ = new TestContext();
const testOrg = new MockTestOrgData();
const config = new Config({ root: resolve(__dirname, '../../../package.json') });
beforeEach(async () => {
await $$.stubAuths(testOrg);
await config.load();
$$.fakeConnectionRequest = (request: AnyJson): Promise<SaveResult> => {
const requestWithUrl = ensureJsonMap(request);
if (request && ensureString(requestWithUrl.url).includes('Account')) {
return Promise.resolve({
id: sObjectId,
success: true,
errors: undefined,
});
}
};
});
it('should create a new sobject', async () => {
const cmd = new Create(
['--targetusername', 'test@org.com', '--sobjecttype', 'Account', '-v', '"Name=Acme"', '--json'],
config
);
const result = (await cmd.run()) as unknown as SaveResult;
expect(result.id).to.equal(sObjectId);
});
});