Skip to content

Commit

Permalink
feat: base.getOrganizaions (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
miyajan authored Jul 16, 2020
1 parent a327b60 commit a4c87cb
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/base.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Base

- [getUsers](#getusers)
- [getOrganizations](#getorganizations)

## Overview

Expand Down Expand Up @@ -40,3 +41,23 @@ See the example response in the `Reference`.
#### Reference

- https://developer.cybozu.io/hc/ja/articles/360018124651#step1

### getOrganizations

Get organizations specified by conditions.

#### Parameters

| Name | Type | Required | Description |
| ------ | :----: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------ |
| limit | Number | | The number of organizations to retrieve.<br />Must be between `1` and `1000`.<br />If nothing is specified, it will default to `100`. |
| offset | Number | | The number of retrievals that will be skipped.<br />Must be between `0` and `2147483647`. If nothing is specified, it will default to `0`. |
| name | String | | The name for searching organizations. |

#### Returns

See the example response in the `Reference`.

#### Reference

- https://developer.cybozu.io/hc/ja/articles/360017843172#step1
19 changes: 19 additions & 0 deletions src/client/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,27 @@ export class BaseClient {
name: string;
code: string;
}>;
hasNext: boolean;
}> {
const path = buildPath({ endpointName: "base/users" });
return this.client.get(path, params ?? {});
}

public getOrganizations(params?: {
limit?: number;
offset?: number;
name?: string;
}): Promise<{
organizations: Array<{
id: string;
name: string;
code: string;
parentOrganization: string;
childOrganizations: Array<{ id: string }>;
}>;
hasNext: boolean;
}> {
const path = buildPath({ endpointName: "base/organizations" });
return this.client.get(path, params ?? {});
}
}
20 changes: 20 additions & 0 deletions src/client/__tests__/BaseClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,24 @@ describe("BaseClient", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});

describe("getOrganizations", () => {
const params = {
limit: 100,
offset: 0,
name: "test",
};
beforeEach(async () => {
await baseClient.getOrganizations(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/api/v1/base/organizations");
});
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);
});
});
});

0 comments on commit a4c87cb

Please sign in to comment.