diff --git a/sdk/src/SDK.ts b/sdk/src/SDK.ts index a4ba3b4..b7d3698 100644 --- a/sdk/src/SDK.ts +++ b/sdk/src/SDK.ts @@ -122,8 +122,8 @@ export class SDK { this.platform().send({method: 'PATCH', url, query, body, ...options}); /* istanbul ignore next */ - public delete = async (url, query?, options?: SendOptions): Promise => - this.platform().send({method: 'DELETE', url, query, ...options}); + public delete = async (url, body?, query?, options?: SendOptions): Promise => + this.platform().send({method: 'DELETE', url, query, body, ...options}); /* istanbul ignore next */ public login = async (options: LoginOptions): Promise => this.platform().login(options); diff --git a/sdk/src/platform/Platform-spec.ts b/sdk/src/platform/Platform-spec.ts index 3133b80..0252480 100644 --- a/sdk/src/platform/Platform-spec.ts +++ b/sdk/src/platform/Platform-spec.ts @@ -705,6 +705,57 @@ describe('RingCentral.platform.Platform', () => { expect(request.headers.get('x-user-agent')).toContain('TestAgent'); }), ); + + it( + 'DELETE without body', + asyncTest(async sdk => { + const platform = sdk.platform(); + const client = sdk.client(); + const path = `/restapi/v1.0/foo/delete-no-body`; + + apiCall('DELETE', path, {ok: true}); + + let request; + client.on(client.events.requestSuccess, (_, r) => { + request = r; + }); + + const res = await platform.delete(path); + const json = await res.json(); + + expect(json.ok).toEqual(true); + expect(request.method).toEqual('DELETE'); + expect(request.url).toEqual(`http://whatever${path}`); + expect(request.headers.get('content-type')).toContain('application/json'); + expect(request['originalBody']).toEqual(undefined); + }), + ); + + it( + 'DELETE with JSON body', + asyncTest(async sdk => { + const platform = sdk.platform(); + const client = sdk.client(); + const path = `/restapi/v1.0/foo/delete-with-body`; + + apiCall('DELETE', path, {ok: true}); + + let request; + client.on(client.events.requestSuccess, (_, r) => { + request = r; + }); + + const payload = {reason: 'cleanup', force: true}; + const res = await platform.delete(path, payload); + const json = await res.json(); + + expect(json.ok).toEqual(true); + expect(request.method).toEqual('DELETE'); + expect(request.url).toEqual(`http://whatever${path}`); + expect(request.headers.get('content-type')).toContain('application/json'); + expect(request['originalBody']).toEqual(JSON.stringify(payload)); + }), + ); }); describe('createUrl', () => { diff --git a/sdk/src/platform/Platform.ts b/sdk/src/platform/Platform.ts index e79de49..c8d85c8 100644 --- a/sdk/src/platform/Platform.ts +++ b/sdk/src/platform/Platform.ts @@ -811,8 +811,8 @@ export default class Platform extends EventEmitter { return this.send({method: 'PATCH', url, query, body, ...options}); } - public async delete(url, query?, options?: SendOptions): Promise { - return this.send({method: 'DELETE', url, query, ...options}); + public async delete(url, body?, query?, options?: SendOptions): Promise { + return this.send({method: 'DELETE', url, query, body, ...options}); } public async ensureLoggedIn(): Promise {