From 00390a8135895635cc244eb23783060484947a40 Mon Sep 17 00:00:00 2001 From: Miyata Jumpei Date: Mon, 13 Jul 2020 21:20:15 +0900 Subject: [PATCH] feat: `workflow.getFile` (#42) --- docs/workflow.md | 19 +++++++++++++++++++ src/client/WorkflowClient.ts | 14 ++++++++++++++ src/client/__tests__/WorkflowClient.test.ts | 17 +++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/docs/workflow.md b/docs/workflow.md index d01b961..1aead61 100644 --- a/docs/workflow.md +++ b/docs/workflow.md @@ -1,6 +1,7 @@ # Workflow - [getRequests](#getrequests) +- [getFile](#getfile) ## Overview @@ -47,3 +48,21 @@ See the example response in the `Reference`. #### Reference - https://developer.cybozu.io/hc/ja/articles/360031071011#step1 + +### getFile + +Get a file attached to a request. + +#### Parameters + +| Name | Type | Required | Description | +| ---- | :--------------: | :------: | ------------ | +| id | Number or String | Yes | The file ID. | + +#### Returns + +See the example response in the `Reference`. + +#### Reference + +- https://developer.cybozu.io/hc/ja/articles/360031071011#step2 diff --git a/src/client/WorkflowClient.ts b/src/client/WorkflowClient.ts index e1d9bf6..90b8ec4 100644 --- a/src/client/WorkflowClient.ts +++ b/src/client/WorkflowClient.ts @@ -100,4 +100,18 @@ export class WorkflowClient { } return this.client.get(path, data); } + + public getFile(params: { + id: string | number; + }): Promise<{ + id: string; + contentType: string; + name: string; + size: string; + content: string; + }> { + const { id } = params; + const path = buildPath({ endpointName: `workflow/admin/files/${id}` }); + return this.client.get(path, {}); + } } diff --git a/src/client/__tests__/WorkflowClient.test.ts b/src/client/__tests__/WorkflowClient.test.ts index ca2bddc..0377599 100644 --- a/src/client/__tests__/WorkflowClient.test.ts +++ b/src/client/__tests__/WorkflowClient.test.ts @@ -59,4 +59,21 @@ describe("WorkflowClient", () => { }); }); }); + + describe("getFile", () => { + beforeEach(async () => { + await workflowClient.getFile({ id: 1 }); + }); + it("should pass the path to the http client", () => { + expect(mockClient.getLogs()[0].path).toBe( + "/api/v1/workflow/admin/files/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({}); + }); + }); });