Skip to content

Commit

Permalink
feat: schedule.deleteEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
miyajan committed Jul 6, 2020
1 parent e5c6c1b commit e6cc3be
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
20 changes: 20 additions & 0 deletions docs/schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [getEvents](#getevents)
- [addEvent](#addevent)
- [updateEvent](#updateevent)
- [deleteEvent](#deleteevent)

## Overview

Expand Down Expand Up @@ -135,6 +136,7 @@ Update an event by specifying the event ID. A tentative event cannot be updated

| Name | Type | Required | Description |
| -------------------------- | :--------------: | :-------------------------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id | Number or String | Yes | The event ID. |
| eventMenu | String | | The event menu. An empty string is taken as the default setting ("-----"). |
| subject | String | | The event subject. |
| notes | String | | The event memo. |
Expand Down Expand Up @@ -178,3 +180,21 @@ See the example response in the `Reference`.
#### Reference

- https://developer.cybozu.io/hc/ja/articles/360000495746#step1

### deleteEvent

Delete an event by specifying the event ID. If an ID of a repeating event is specified, all ranges of the event will be deleted. A tentative event cannot be deleted by this API.

#### Parameters

| Name | Type | Required | Description |
| ---- | :--------------: | :------: | ------------- |
| id | Number or String | Yes | The event ID. |

#### Returns

See the example response in the `Reference`.

#### Reference

- https://developer.cybozu.io/hc/ja/articles/360000393866
6 changes: 2 additions & 4 deletions src/GaroonRequestConfigBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,11 @@ export class GaroonRequestConfigBuilder implements RequestConfigBuilder {
};
}
case "delete": {
const requestUrl = this.buildRequestUrl(
path,
await this.buildData(params)
);
const requestUrl = this.buildRequestUrl(path, params);
return {
...requestConfig,
url: requestUrl,
data: await this.buildData({}),
};
}
default: {
Expand Down
6 changes: 5 additions & 1 deletion src/__tests__/GaroonRequestConfigBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe("GaroonRequestConfigBuilder", () => {
"User-Agent": expectedUa,
"X-Cybozu-Authorization": expectedAuth,
},
data: {},
});
});
});
Expand Down Expand Up @@ -185,10 +186,13 @@ describe("GaroonRequestConfigBuilder", () => {
expect(requestConfig).toStrictEqual({
method: "delete",
proxy: undefined,
url: `${baseUrl}/api/v1/schedule/events/1?__REQUEST_TOKEN__=${requestToken}&key=value`,
url: `${baseUrl}/api/v1/schedule/events/1?key=value`,
headers: {
"X-Requested-With": "XMLHttpRequest",
},
data: {
__REQUEST_TOKEN__: requestToken,
},
});
});
});
Expand Down
6 changes: 6 additions & 0 deletions src/client/ScheduleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,10 @@ export class ScheduleClient {
const path = buildPath({ endpointName: `schedule/events/${id}` });
return this.client.patch(path, event);
}

public async deleteEvent(params: { id: EventID }): Promise<void> {
const { id } = params;
const path = buildPath({ endpointName: `schedule/events/${id}` });
await this.client.delete(path, {});
}
}
18 changes: 18 additions & 0 deletions src/client/__tests__/ScheduleClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,22 @@ describe("ScheduleClient", () => {
expect(mockClient.getLogs()[0].params).toEqual(params.event);
});
});

describe("deleteEvent", () => {
const params = {
id: "1",
};
beforeEach(async () => {
await scheduleClient.deleteEvent(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/api/v1/schedule/events/1");
});
it("should send a delete request", () => {
expect(mockClient.getLogs()[0].method).toBe("delete");
});
it("should pass an empty object as a param to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual({});
});
});
});

0 comments on commit e6cc3be

Please sign in to comment.