Skip to content

Commit 4d21123

Browse files
committed
chore: cover null cases for test
1 parent 56da1b9 commit 4d21123

4 files changed

Lines changed: 29 additions & 18 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"shx": "0.3.4",
4343
"sinon": "10.0.0",
4444
"ts-node": "^10.0.0",
45-
"typescript": "^4.9.3"
45+
"typescript": "^4.9.5"
4646
},
4747
"config": {},
4848
"engines": {
@@ -110,4 +110,4 @@
110110
"publishConfig": {
111111
"access": "public"
112112
}
113-
}
113+
}

test/commands/sobject/list.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ describe('force:schema:sobject:list', () => {
8181
sobjects: [],
8282
});
8383
}
84+
throw new Error('Unexpected request');
8485
};
8586
const cmd = new SObjectList(['-u', 'testUser@test.com'], config);
8687

test/schema.nut.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77
import * as path from 'path';
8+
import { strict as assert } from 'node:assert';
89
import { expect } from 'chai';
910
import { DescribeSObjectResult } from 'jsforce';
1011
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
12+
import { SObjectListResult } from '../src/commands/sobject/list';
1113

1214
let session: TestSession;
1315

@@ -63,32 +65,35 @@ describe('verifies all commands run successfully ', () => {
6365

6466
describe('list command', () => {
6567
it('requests all objects by default', () => {
66-
const output = execCmd<string[]>('force:schema:sobject:list --json', { ensureExitCode: 0 }).jsonOutput;
67-
expect(output.result).to.have.length.greaterThan(1);
68-
allObjects = output.result;
68+
const result = execCmd<SObjectListResult>('force:schema:sobject:list --json', { ensureExitCode: 0 }).jsonOutput
69+
?.result;
70+
assert(result?.length);
71+
expect(result).to.have.length.greaterThan(1);
72+
allObjects = result;
6973
});
7074

7175
it('requests all objects explicity', () => {
72-
const output = execCmd<string[]>('force:schema:sobject:list --json --sobjecttypecategory ALL', {
76+
const result = execCmd<SObjectListResult>('force:schema:sobject:list --json --sobjecttypecategory ALL', {
7377
ensureExitCode: 0,
74-
}).jsonOutput;
75-
expect(output.result).to.have.length(allObjects.length);
76-
allObjects = output.result;
78+
}).jsonOutput?.result;
79+
assert(result);
80+
expect(result).to.have.length(allObjects.length);
81+
allObjects = result;
7782
});
7883

7984
it('requests standard objects', () => {
80-
const output = execCmd<string[]>('force:schema:sobject:list --json --sobjecttypecategory STANDARD', {
85+
const result = execCmd<SObjectListResult>('force:schema:sobject:list --json --sobjecttypecategory STANDARD', {
8186
ensureExitCode: 0,
82-
}).jsonOutput;
87+
}).jsonOutput?.result;
8388
// all the objects are standard in a vanilla scratch org
84-
expect(output.result).to.have.length(allObjects.length);
89+
expect(result).to.have.length(allObjects.length);
8590
});
8691

8792
it('requests custom objects but finds none in vanilla scratch org', () => {
88-
const output = execCmd<string[]>('force:schema:sobject:list --json --sobjecttypecategory CUSTOM', {
93+
const result = execCmd<SObjectListResult>('force:schema:sobject:list --json --sobjecttypecategory CUSTOM', {
8994
ensureExitCode: 0,
90-
}).jsonOutput;
91-
expect(output.result).to.have.length(0);
95+
}).jsonOutput?.result;
96+
expect(result).to.have.length(0);
9297
});
9398

9499
it('no errors on non-json commands', () => {
@@ -104,14 +109,14 @@ describe('verifies all commands run successfully ', () => {
104109
const output = execCmd<DescribeSObjectResult>('force:schema:sobject:describe --sobjecttype Account --json', {
105110
ensureExitCode: 0,
106111
}).jsonOutput;
107-
expect(output.result).to.include.keys(objectDescribeKeys);
112+
expect(output?.result).to.include.keys(objectDescribeKeys);
108113
});
109114

110115
it('describes ApexClass via toolingApi', () => {
111116
const output = execCmd<DescribeSObjectResult>('force:schema:sobject:describe --sobjecttype ApexClass -t --json', {
112117
ensureExitCode: 0,
113118
}).jsonOutput;
114-
expect(output.result).to.include.keys(objectDescribeKeys);
119+
expect(output?.result).to.include.keys(objectDescribeKeys);
115120
});
116121

117122
it('no errors on non-json commands', () => {

yarn.lock

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7189,11 +7189,16 @@ typedoc@0.22.18:
71897189
minimatch "^5.1.0"
71907190
shiki "^0.10.1"
71917191

7192-
typescript@^4.1.3, typescript@^4.6.4, typescript@^4.9.3, typescript@~4.9.3:
7192+
typescript@^4.1.3, typescript@^4.6.4, typescript@~4.9.3:
71937193
version "4.9.4"
71947194
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.4.tgz#a2a3d2756c079abda241d75f149df9d561091e78"
71957195
integrity sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==
71967196

7197+
typescript@^4.9.5:
7198+
version "4.9.5"
7199+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
7200+
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==
7201+
71977202
uglify-js@^3.1.4:
71987203
version "3.15.3"
71997204
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.15.3.tgz#9aa82ca22419ba4c0137642ba0df800cb06e0471"

0 commit comments

Comments
 (0)