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: presence.updatePresenceByUserID #50

Merged
merged 1 commit into from
Aug 16, 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
24 changes: 23 additions & 1 deletion docs/presence.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [getPresenceByUserID](#getpresencebyuserid)
- [getPresenceByUserCode](#getpresencebyusercode)
- [updatePresenceByUserID](#updatepresencebyuserid)

## Overview

Expand All @@ -24,7 +25,7 @@ const client = new GaroonRestAPIClient();

### getPresenceByUserID

Get the presence information specified by the user id.
Get the presence information specified by the user ID.

#### Parameters

Expand Down Expand Up @@ -57,3 +58,24 @@ See the example response in the `Reference`.
#### Reference

- https://developer.cybozu.io/hc/ja/articles/360026939891#step2

### updatePresenceByUserID

Update the presence information specified by the user ID.

#### Parameters

| Name | Type | Required | Description |
| ----------- | :--------------: | :------: | -------------------------------------------- |
| id | Number or String | Yes | The user ID. |
| status | Object | | An object containing data of the status. |
| status.code | String | | The status code of the presence information. |
| notes | String | | The memo. |

#### Returns

See the example response in the `Reference`.

#### Reference

- https://developer.cybozu.io/hc/ja/articles/360026939911#step1
13 changes: 13 additions & 0 deletions src/client/PresenceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,17 @@ export class PresenceClient {
const path = buildPath({ endpointName: `presence/users/code/${code}` });
return this.client.get(path, {});
}

public updatePresenceByUserID(params: {
id: string | number;
status?: {
code?: string;
};
notes?: string;
}): Promise<Presence> {
const { id, ...rest } = params;
const path = buildPath({ endpointName: `presence/users/${id}` });
const data = (rest as unknown) as Record<string, unknown>;
return this.client.patch(path, data);
}
}
27 changes: 27 additions & 0 deletions src/client/__tests__/PresenceClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,31 @@ describe("PresenceClient", () => {
expect(mockClient.getLogs()[0].params).toEqual({});
});
});

describe("updatePresenceByUserID", () => {
const params = {
id: 1,
status: {
code: "attend",
},
notes: "This is presence note.",
};
beforeEach(async () => {
await presenceClient.updatePresenceByUserID(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/api/v1/presence/users/1");
});
it("should send a patch request", () => {
expect(mockClient.getLogs()[0].method).toBe("patch");
});
it("should pass status and notes as a param to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual({
status: {
code: "attend",
},
notes: "This is presence note.",
});
});
});
});