From 63ed8238b4f3a90250defd47f5ccead6bfff496f Mon Sep 17 00:00:00 2001 From: Miyata Jumpei Date: Wed, 8 Jul 2020 22:12:14 +0900 Subject: [PATCH] feat: schedule.getFacilities (#37) --- docs/schedule.md | 21 +++++++++++++++++++++ src/client/ScheduleClient.ts | 18 ++++++++++++++++++ src/client/__tests__/ScheduleClient.test.ts | 20 ++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/docs/schedule.md b/docs/schedule.md index c7756bc..6f64812 100644 --- a/docs/schedule.md +++ b/docs/schedule.md @@ -6,6 +6,7 @@ - [updateEvent](#updateevent) - [deleteEvent](#deleteevent) - [searchAvailableTimes](#searchavailabletimes) +- [getFacilities](#getfacilities) ## Overview @@ -228,3 +229,23 @@ See the example response in the `Reference`. #### Reference - https://developer.cybozu.io/hc/ja/articles/360018417771#step1 + +### getFacilities + +Get facilities by specifying conditions. + +#### Parameters + +| Name | Type | Required | Description | +| ------ | :----: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------ | +| limit | number | | The number of facilities to retrieve.
Must be between `1` and `1000`.
If nothing is specified, it will default to `100`. | +| offset | Number | | The number of retrievals that will be skipped.
Must be between `0` and `2147483647`. If nothing is specified, it will default to `0`. | +| name | String | | The facility name. | + +#### Returns + +See the example response in the `Reference`. + +#### Reference + +- https://developer.cybozu.io/hc/ja/articles/360017764211#step1 diff --git a/src/client/ScheduleClient.ts b/src/client/ScheduleClient.ts index b991c1a..d2fdd8b 100644 --- a/src/client/ScheduleClient.ts +++ b/src/client/ScheduleClient.ts @@ -203,4 +203,22 @@ export class ScheduleClient { const path = buildPath({ endpointName: "schedule/searchAvailableTimes" }); return this.client.post(path, params); } + + public getFacilities(params: { + limit?: number; + offset?: number; + name?: string; + }): Promise<{ + facilities: Array<{ + id: string; + name: string; + code: string; + notes: string; + facilityGroup: string; + }>; + hasNext: boolean; + }> { + const path = buildPath({ endpointName: "schedule/facilities" }); + return this.client.get(path, params); + } } diff --git a/src/client/__tests__/ScheduleClient.test.ts b/src/client/__tests__/ScheduleClient.test.ts index 1c50e3f..f5b229a 100644 --- a/src/client/__tests__/ScheduleClient.test.ts +++ b/src/client/__tests__/ScheduleClient.test.ts @@ -284,4 +284,24 @@ describe("ScheduleClient", () => { expect(mockClient.getLogs()[0].params).toEqual(params); }); }); + + describe("getFacilities", () => { + const params = { + limit: 100, + offset: 0, + name: "Facility", + }; + beforeEach(async () => { + await scheduleClient.getFacilities(params); + }); + it("should pass the path to the http client", () => { + expect(mockClient.getLogs()[0].path).toBe("/api/v1/schedule/facilities"); + }); + it("should send a get request", () => { + expect(mockClient.getLogs()[0].method).toBe("get"); + }); + it("should pass params as a param to the http client", () => { + expect(mockClient.getLogs()[0].params).toEqual(params); + }); + }); });