Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: notification.addItem #54

Merged
merged 1 commit into from
Aug 21, 2020
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
29 changes: 29 additions & 0 deletions docs/notification.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Notification

- [getItems](#getitems)
- [addItem](#additem)

## Overview

Expand Down Expand Up @@ -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\<Object\> | Yes | The list of the notification destinations. |
| destinations[].type | String | Yes | The destination type. Possible value is: `USER`. |
| destinations[].id | String or Number | Conditionally<br />Required | The ID of the destination. Required if `destinations[].code` is not specified. |
| destinations[].code | String | Conditionally<br />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
33 changes: 33 additions & 0 deletions src/client/NotificationClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
30 changes: 30 additions & 0 deletions src/client/__tests__/NotificationClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});