Skip to content

Commit

Permalink
feat: presence.getPresenceByUserCode (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
miyajan authored Jul 21, 2020
1 parent 8d60176 commit c2b8708
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 13 deletions.
19 changes: 19 additions & 0 deletions docs/presence.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Presence

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

## Overview

Expand Down Expand Up @@ -38,3 +39,21 @@ See the example response in the `Reference`.
#### Reference

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

### getPresenceByUserCode

Get the presence information specified by the code of the user.

#### Parameters

| Name | Type | Required | Description |
| ---- | :----: | :------: | --------------------- |
| code | String | Yes | The code of the user. |

#### Returns

See the example response in the `Reference`.

#### Reference

- https://developer.cybozu.io/hc/ja/articles/360026939891#step2
21 changes: 8 additions & 13 deletions src/client/PresenceClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HttpClient } from "../http";
import { Presence } from "./types";
import { buildPath } from "../url";

export class PresenceClient {
Expand All @@ -10,21 +11,15 @@ export class PresenceClient {

public getPresenceByUserID(params: {
id: string | number;
}): Promise<{
user: {
id: string;
name: string;
code: string;
};
updatedAt: string;
notes: string;
status: {
name: string;
code: string;
};
}> {
}): Promise<Presence> {
const { id } = params;
const path = buildPath({ endpointName: `presence/users/${id}` });
return this.client.get(path, {});
}

public getPresenceByUserCode(params: { code: string }): Promise<Presence> {
const { code } = params;
const path = buildPath({ endpointName: `presence/users/code/${code}` });
return this.client.get(path, {});
}
}
18 changes: 18 additions & 0 deletions src/client/__tests__/PresenceClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,22 @@ describe("PresenceClient", () => {
expect(mockClient.getLogs()[0].params).toEqual({});
});
});

describe("getPresenceByUserCode", () => {
const params = { code: "cybozu" };
beforeEach(async () => {
await presenceClient.getPresenceByUserCode(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe(
"/api/v1/presence/users/code/cybozu"
);
});
it("should send a get request", () => {
expect(mockClient.getLogs()[0].method).toBe("get");
});
it("should pass an empty object as a param to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual({});
});
});
});
1 change: 1 addition & 0 deletions src/client/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./schedule";
export * from "./workflow";
export * from "./presence";
13 changes: 13 additions & 0 deletions src/client/types/presence/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export type Presence = {
user: {
id: string;
name: string;
code: string;
};
updatedAt: string;
notes: string;
status: {
name: string;
code: string;
};
};

0 comments on commit c2b8708

Please sign in to comment.