Skip to content

Commit

Permalink
feat: presence.getPresenceByUserID (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
miyajan authored Jul 17, 2020
1 parent 3a081b1 commit 8d60176
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const client = new GaroonRestAPIClient();

(async () => {
try {
console.log(await client.base.getUsers);
console.log(await client.base.getUsers());
} catch (error) {
console.log(error);
}
Expand Down
40 changes: 40 additions & 0 deletions docs/presence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Presence

- [getPresenceByUserID](#getpresencebyuserid)

## Overview

```ts
const client = new GaroonRestAPIClient();

(async () => {
try {
console.log(await client.presence.getPresenceByUserID({ id: 1 }));
} catch (error) {
console.log(error);
}
})();
```

- All methods are defined on the `presence` property.
- This method returns a Promise object that is resolved with an object having properties in each `Returns` section.

## Methods

### getPresenceByUserID

Get the presence information specified by the user id.

#### Parameters

| Name | Type | Required | Description |
| ---- | :--------------: | :------: | ------------ |
| id | Number or String | Yes | The user ID. |

#### Returns

See the example response in the `Reference`.

#### Reference

- https://developer.cybozu.io/hc/ja/articles/360026939891#step1
3 changes: 3 additions & 0 deletions src/GaroonRestAPIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { UnsupportedPlatformError } from "./platform/UnsupportedPlatformError";
import { GaroonRequestConfigBuilder } from "./GaroonRequestConfigBuilder";
import { WorkflowClient } from "./client/WorkflowClient";
import { BaseClient } from "./client/BaseClient";
import { PresenceClient } from "./client/PresenceClient";

export type DiscriminatedAuth = PasswordAuth | SessionAuth | OAuthTokenAuth;

Expand Down Expand Up @@ -97,6 +98,7 @@ export class GaroonRestAPIClient {
readonly schedule: ScheduleClient;
readonly workflow: WorkflowClient;
readonly base: BaseClient;
readonly presence: PresenceClient;
private readonly baseUrl: string;

constructor(options: Options = {}) {
Expand All @@ -115,6 +117,7 @@ export class GaroonRestAPIClient {
this.schedule = new ScheduleClient(httpClient);
this.workflow = new WorkflowClient(httpClient);
this.base = new BaseClient(httpClient);
this.presence = new PresenceClient(httpClient);
}

public getBaseUrl(): string {
Expand Down
30 changes: 30 additions & 0 deletions src/client/PresenceClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { HttpClient } from "../http";
import { buildPath } from "../url";

export class PresenceClient {
private readonly client: HttpClient;

constructor(client: HttpClient) {
this.client = client;
}

public getPresenceByUserID(params: {
id: string | number;
}): Promise<{
user: {
id: string;
name: string;
code: string;
};
updatedAt: string;
notes: string;
status: {
name: string;
code: string;
};
}> {
const { id } = params;
const path = buildPath({ endpointName: `presence/users/${id}` });
return this.client.get(path, {});
}
}
38 changes: 38 additions & 0 deletions src/client/__tests__/PresenceClient.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { MockClient } from "../../http/MockClient";
import { GaroonRequestConfigBuilder } from "../../GaroonRequestConfigBuilder";
import { errorResponseHandler } from "../../GaroonRestAPIClient";
import { PresenceClient } from "../PresenceClient";

describe("PresenceClient", () => {
let mockClient: MockClient;
let presenceClient: PresenceClient;

beforeEach(() => {
const requestConfigBuilder = new GaroonRequestConfigBuilder({
baseUrl: "https://example.cybozu.com/g",
auth: {
type: "password",
username: "cybozu",
password: "cybozu",
},
});
mockClient = new MockClient({ requestConfigBuilder, errorResponseHandler });
presenceClient = new PresenceClient(mockClient);
});

describe("getPresenceByUserID", () => {
const params = { id: 1 };
beforeEach(async () => {
await presenceClient.getPresenceByUserID(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 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({});
});
});
});

0 comments on commit 8d60176

Please sign in to comment.