Skip to content

Commit

Permalink
feat: workflow.getFile (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
miyajan authored Jul 13, 2020
1 parent ede148c commit 00390a8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/workflow.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Workflow

- [getRequests](#getrequests)
- [getFile](#getfile)

## Overview

Expand Down Expand Up @@ -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
14 changes: 14 additions & 0 deletions src/client/WorkflowClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {});
}
}
17 changes: 17 additions & 0 deletions src/client/__tests__/WorkflowClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
});
});
});

0 comments on commit 00390a8

Please sign in to comment.