Skip to content

Commit

Permalink
feat: presence.updatePresenceByUserID (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
miyajan authored Aug 16, 2020
1 parent c2b8708 commit ee54b93
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
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.",
});
});
});
});

0 comments on commit ee54b93

Please sign in to comment.