diff --git a/docs/notification.md b/docs/notification.md index 6e70c86..6563bbf 100644 --- a/docs/notification.md +++ b/docs/notification.md @@ -1,6 +1,7 @@ # Notification - [getItems](#getitems) +- [addItem](#additem) ## Overview @@ -40,3 +41,31 @@ See the example response in the `Reference`. #### Reference - https://developer.cybozu.io/hc/ja/articles/360017764051#step1 + +### addItem + +Add a notification. + +#### Parameters + +| Name | Type | Required | Description | +| ------------------- | :--------------: | :-------------------------: | ---------------------------------------------------------------------------------- | +| app | String | Yes | The external notification code. | +| notificationKey | String | Yes | The notification key. | +| operation | String | Yes | The operation of the notification. Possible values are: `add`, `modify`, `remove`. | +| url | String | Yes | The notification URL. | +| title | String | Yes | The notification title. | +| body | String | Yes | The notification body. | +| icon | String | | The notification icon URL. | +| destinations | Array\ | Yes | The list of the notification destinations. | +| destinations[].type | String | Yes | The destination type. Possible value is: `USER`. | +| destinations[].id | String or Number | Conditionally
Required | The ID of the destination. Required if `destinations[].code` is not specified. | +| destinations[].code | String | Conditionally
Required | The code of the destination. Required if `destinations[].id` is not specified. | + +#### Returns + +See the example response in the `Reference`. + +#### Reference + +- https://developer.cybozu.io/hc/ja/articles/360017482672#step1 diff --git a/src/client/NotificationClient.ts b/src/client/NotificationClient.ts index 893a469..0da9b45 100644 --- a/src/client/NotificationClient.ts +++ b/src/client/NotificationClient.ts @@ -43,4 +43,37 @@ export class NotificationClient { } return this.client.get(path, data); } + + public addItem(params: { + app: string; + notificationKey: string; + operation: "add" | "modify" | "remove"; + url: string; + title: string; + body: string; + icon?: string; + destinations: Array<{ + type: "USER"; + id?: string | number; + code?: string; + }>; + }): Promise<{ + moduleId: string; + notificationKey: string; + creator: { + id: string; + code: string; + name: string; + }; + createdAt: string; + operation: "add" | "modify" | "remove"; + url: string; + title: string; + body: string; + icon: string; + isRead: boolean; + }> { + const path = buildPath({ endpointName: `notification/items` }); + return this.client.post(path, params); + } } diff --git a/src/client/__tests__/NotificationClient.test.ts b/src/client/__tests__/NotificationClient.test.ts index 303d32d..fc44d09 100644 --- a/src/client/__tests__/NotificationClient.test.ts +++ b/src/client/__tests__/NotificationClient.test.ts @@ -43,4 +43,34 @@ describe("NotificationClient", () => { }); }); }); + + describe("addItem", () => { + const params = { + app: "Test", + notificationKey: "test-notification-key", + operation: "add" as const, + url: "http://example.com", + title: "Test title", + body: "Test body", + icon: "http://example.com/example.png", + destinations: [ + { + type: "USER" as const, + id: "1", + }, + ], + }; + beforeEach(async () => { + await notificationClient.addItem(params); + }); + it("should pass the path to the http client", () => { + expect(mockClient.getLogs()[0].path).toBe("/api/v1/notification/items"); + }); + it("should send a post request", () => { + expect(mockClient.getLogs()[0].method).toBe("post"); + }); + it("should pass params as a param to the http client", () => { + expect(mockClient.getLogs()[0].params).toEqual(params); + }); + }); });