Skip to content
Open
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
4 changes: 2 additions & 2 deletions sdk/src/SDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response> =>
this.platform().send({method: 'DELETE', url, query, ...options});
public delete = async (url, body?, query?, options?: SendOptions): Promise<Response> =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a break change. We need to update docs too.

this.platform().send({method: 'DELETE', url, query, body, ...options});

/* istanbul ignore next */
public login = async (options: LoginOptions): Promise<Response> => this.platform().login(options);
Expand Down
51 changes: 51 additions & 0 deletions sdk/src/platform/Platform-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,57 @@
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', () => {
Expand Down Expand Up @@ -973,7 +1024,7 @@
const openSpy = spy(() => null);

window.open = openSpy;
await expectThrows(async () => {

Check warning on line 1027 in sdk/src/platform/Platform-spec.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Update this function so that its implementation is not identical to the one on line 1009

Check warning on line 1027 in sdk/src/platform/Platform-spec.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Update this function so that its implementation is not identical to the one on line 1009
await platform.loginWindow({
url: 'foo',
origin: 'foo',
Expand All @@ -996,7 +1047,7 @@
openWindow.closed = true;
}, 3000);

await expectThrows(async () => {

Check warning on line 1050 in sdk/src/platform/Platform-spec.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Update this function so that its implementation is not identical to the one on line 1009

Check warning on line 1050 in sdk/src/platform/Platform-spec.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Update this function so that its implementation is not identical to the one on line 1009
await platform.loginWindow({
url: 'foo',
origin: 'foo',
Expand Down Expand Up @@ -1099,7 +1150,7 @@
);
});

describe('discovery initial', () => {

Check warning on line 1153 in sdk/src/platform/Platform-spec.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Refactor this function to reduce its Cognitive Complexity from 19 to the 15 allowed

Check warning on line 1153 in sdk/src/platform/Platform-spec.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Refactor this function to reduce its Cognitive Complexity from 19 to the 15 allowed
let sdk;

beforeEach(() => {
Expand Down Expand Up @@ -1240,7 +1291,7 @@
expect(await platform.discovery().externalDataExpired()).toEqual(false);
});

it('should fetch external discovery when login with discovery_uri and token_uri when discoveryInitPromise finished', async () => {

Check warning on line 1294 in sdk/src/platform/Platform-spec.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Update this function so that its implementation is not identical to the one on line 1274

Check warning on line 1294 in sdk/src/platform/Platform-spec.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Update this function so that its implementation is not identical to the one on line 1274
// mock
const initialDiscoveryData = getInitialDiscoveryMockData();
const externalDiscoveryData = getExternalDiscoveryMockData();
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/platform/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
}: LoginWindowOptions): Promise<LoginOptions> {
// clear check last timeout when user open loginWindow twice to avoid leak
this._clearLoginWindowCheckTimeout();
return new Promise((resolve, reject) => {

Check warning on line 365 in sdk/src/platform/Platform.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed

Check warning on line 365 in sdk/src/platform/Platform.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed
if (typeof window === 'undefined') {throw new Error('This method can be used only in browser');}

if (!url) {throw new Error('Missing mandatory URL parameter');}
Expand Down Expand Up @@ -454,7 +454,7 @@
}
}

public async login({

Check warning on line 457 in sdk/src/platform/Platform.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Refactor this function to reduce its Cognitive Complexity from 34 to the 15 allowed

Check warning on line 457 in sdk/src/platform/Platform.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Refactor this function to reduce its Cognitive Complexity from 34 to the 15 allowed
username,
password,
extension = '',
Expand Down Expand Up @@ -574,7 +574,7 @@
return {tokenEndpoint, discoveryEndpoint};
}

private async _refresh(): Promise<Response> {

Check warning on line 577 in sdk/src/platform/Platform.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed

Check warning on line 577 in sdk/src/platform/Platform.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed
try {
this.emit(this.events.beforeRefresh);

Expand Down Expand Up @@ -717,12 +717,12 @@
return request;
}

public async sendRequest(request: Request, options: SendOptions = {}): Promise<Response> {

Check warning on line 720 in sdk/src/platform/Platform.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed

Check warning on line 720 in sdk/src/platform/Platform.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed
try {
request = await this.inflateRequest(request, options);
return await this._client.sendRequest(request);
} catch (e) {
let {retry, handleRateLimit} = options;

Check warning on line 725 in sdk/src/platform/Platform.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

'retry' is never reassigned. Use 'const' instead

Check warning on line 725 in sdk/src/platform/Platform.ts

View workflow job for this annotation

GitHub Actions / Test (22.x)

'retry' is never reassigned. Use 'const' instead

// Guard is for errors that come from polling
if (!e.response || retry) {throw e;}
Expand Down Expand Up @@ -811,8 +811,8 @@
return this.send({method: 'PATCH', url, query, body, ...options});
}

public async delete(url, query?, options?: SendOptions): Promise<Response> {
return this.send({method: 'DELETE', url, query, ...options});
public async delete(url, body?, query?, options?: SendOptions): Promise<Response> {
return this.send({method: 'DELETE', url, query, body, ...options});
}

public async ensureLoggedIn(): Promise<Response | null> {
Expand Down
Loading