|
| 1 | +import { MockClient } from "../../http/MockClient"; |
| 2 | +import { ScheduleClient } from "../ScheduleClient"; |
| 3 | +import { GaroonRequestConfigBuilder } from "../../GaroonRequestConfigBuilder"; |
| 4 | +import { errorResponseHandler } from "../../GaroonRestAPIClient"; |
| 5 | + |
| 6 | +describe("ScheduleClient", () => { |
| 7 | + let mockClient: MockClient; |
| 8 | + let scheduleClient: ScheduleClient; |
| 9 | + |
| 10 | + beforeEach(() => { |
| 11 | + const requestConfigBuilder = new GaroonRequestConfigBuilder({ |
| 12 | + baseUrl: "https://example.cybozu.com/g", |
| 13 | + auth: { |
| 14 | + type: "session", |
| 15 | + }, |
| 16 | + }); |
| 17 | + mockClient = new MockClient({ requestConfigBuilder, errorResponseHandler }); |
| 18 | + scheduleClient = new ScheduleClient(mockClient); |
| 19 | + }); |
| 20 | + |
| 21 | + describe("getEvent", () => { |
| 22 | + beforeEach(async () => { |
| 23 | + await scheduleClient.getEvent({ id: 1 }); |
| 24 | + }); |
| 25 | + it("should pass the path to the http client", () => { |
| 26 | + expect(mockClient.getLogs()[0].path).toBe("/api/v1/schedule/events/1"); |
| 27 | + }); |
| 28 | + it("should send a get request", () => { |
| 29 | + expect(mockClient.getLogs()[0].method).toBe("get"); |
| 30 | + }); |
| 31 | + it("should pass an empty object as a param to the http client", () => { |
| 32 | + expect(mockClient.getLogs()[0].params).toEqual({}); |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + describe("getEvents", () => { |
| 37 | + describe("without parameter", () => { |
| 38 | + beforeEach(async () => { |
| 39 | + await scheduleClient.getEvents(); |
| 40 | + }); |
| 41 | + it("should pass the path to the http client", () => { |
| 42 | + expect(mockClient.getLogs()[0].path).toBe("/api/v1/schedule/events"); |
| 43 | + }); |
| 44 | + it("should send a get request", () => { |
| 45 | + expect(mockClient.getLogs()[0].method).toBe("get"); |
| 46 | + }); |
| 47 | + it("should pass an empty object as a param to the http client", () => { |
| 48 | + expect(mockClient.getLogs()[0].params).toEqual({}); |
| 49 | + }); |
| 50 | + }); |
| 51 | + describe("with parameter", () => { |
| 52 | + beforeEach(async () => { |
| 53 | + await scheduleClient.getEvents({ |
| 54 | + limit: 100, |
| 55 | + offset: 0, |
| 56 | + fields: ["id", "creator"], |
| 57 | + orderBy: { |
| 58 | + property: "createdAt", |
| 59 | + order: "asc", |
| 60 | + }, |
| 61 | + rangeStart: "2017-10-19T00:10:30Z", |
| 62 | + rangeEnd: "2017-10-19T01:10:30Z", |
| 63 | + target: 1, |
| 64 | + targetType: "user", |
| 65 | + keyword: "test", |
| 66 | + excludeFromSearch: ["subject", "company"], |
| 67 | + }); |
| 68 | + }); |
| 69 | + it("should pass the path to the http client", () => { |
| 70 | + expect(mockClient.getLogs()[0].path).toBe("/api/v1/schedule/events"); |
| 71 | + }); |
| 72 | + it("should send a get request", () => { |
| 73 | + expect(mockClient.getLogs()[0].method).toBe("get"); |
| 74 | + }); |
| 75 | + it("should pass limit, offset, fields, orderBy, rangeStart, rangeEnd, target, targetType, keyword and excludeFromSearch as a param to the http client", () => { |
| 76 | + expect(mockClient.getLogs()[0].params).toEqual({ |
| 77 | + limit: 100, |
| 78 | + offset: 0, |
| 79 | + fields: "id,creator", |
| 80 | + orderBy: "createdAt asc", |
| 81 | + rangeStart: "2017-10-19T00:10:30Z", |
| 82 | + rangeEnd: "2017-10-19T01:10:30Z", |
| 83 | + target: 1, |
| 84 | + targetType: "user", |
| 85 | + keyword: "test", |
| 86 | + excludeFromSearch: "subject,company", |
| 87 | + }); |
| 88 | + }); |
| 89 | + }); |
| 90 | + }); |
| 91 | +}); |
0 commit comments