Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/commands/api/request/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,17 @@ export class Rest extends SfCommand<ApiResponseResult> {
// body can be undefined;
// if we have a --body @myfile.json, read the file
// if we have a --body '{"key":"value"}' use that
// else read from --file's body
// else read from --file's body, if it has one
// with neither (or --body ''), send no body, e.g. for DELETE
let body;
if (method !== 'GET') {
if (flags.body?.startsWith('@')) {
// remove the '@' and read it
body = readFileSync(flags.body.substring(1));
} else if (flags.body) {
body = flags.body;
} else if (!flags.body) {
body = getBodyContents(fileOptions?.body);
} else if (flags.body === undefined && fileOptions?.body) {
body = getBodyContents(fileOptions.body);
}
}

Expand Down
24 changes: 24 additions & 0 deletions test/commands/api/request/rest/rest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,30 @@ describe('rest', () => {
}
});

it('should send a DELETE without a body when neither --body nor --file is given', async () => {
nock(testOrg.instanceUrl).delete('/services/data/v56.0/sobjects/Account/001', '').reply(204);

await Rest.run(['/services/data/v56.0/sobjects/Account/001', '--method', 'DELETE', '--target-org', 'test@hub.com']);

expect(nock.isDone()).to.be.true;
});

it('should send a DELETE without a body when --body is empty', async () => {
nock(testOrg.instanceUrl).delete('/services/data/v56.0/sobjects/Account/001', '').reply(204);

await Rest.run([
'/services/data/v56.0/sobjects/Account/001',
'--method',
'DELETE',
'--body',
'',
'--target-org',
'test@hub.com',
]);

expect(nock.isDone()).to.be.true;
});

it('should not follow redirects', async () => {
nock(testOrg.instanceUrl)
.get('/services/data/v56.0/limites')
Expand Down
Loading