Skip to content

Commit a4c87cb

Browse files
authored
feat: base.getOrganizaions (#46)
1 parent a327b60 commit a4c87cb

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

docs/base.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Base
22

33
- [getUsers](#getusers)
4+
- [getOrganizations](#getorganizations)
45

56
## Overview
67

@@ -40,3 +41,23 @@ See the example response in the `Reference`.
4041
#### Reference
4142

4243
- https://developer.cybozu.io/hc/ja/articles/360018124651#step1
44+
45+
### getOrganizations
46+
47+
Get organizations specified by conditions.
48+
49+
#### Parameters
50+
51+
| Name | Type | Required | Description |
52+
| ------ | :----: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------ |
53+
| 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`. |
54+
| 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`. |
55+
| name | String | | The name for searching organizations. |
56+
57+
#### Returns
58+
59+
See the example response in the `Reference`.
60+
61+
#### Reference
62+
63+
- https://developer.cybozu.io/hc/ja/articles/360017843172#step1

src/client/BaseClient.ts

+19
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,27 @@ export class BaseClient {
1818
name: string;
1919
code: string;
2020
}>;
21+
hasNext: boolean;
2122
}> {
2223
const path = buildPath({ endpointName: "base/users" });
2324
return this.client.get(path, params ?? {});
2425
}
26+
27+
public getOrganizations(params?: {
28+
limit?: number;
29+
offset?: number;
30+
name?: string;
31+
}): Promise<{
32+
organizations: Array<{
33+
id: string;
34+
name: string;
35+
code: string;
36+
parentOrganization: string;
37+
childOrganizations: Array<{ id: string }>;
38+
}>;
39+
hasNext: boolean;
40+
}> {
41+
const path = buildPath({ endpointName: "base/organizations" });
42+
return this.client.get(path, params ?? {});
43+
}
2544
}

src/client/__tests__/BaseClient.test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,24 @@ describe("BaseClient", () => {
3939
expect(mockClient.getLogs()[0].params).toEqual(params);
4040
});
4141
});
42+
43+
describe("getOrganizations", () => {
44+
const params = {
45+
limit: 100,
46+
offset: 0,
47+
name: "test",
48+
};
49+
beforeEach(async () => {
50+
await baseClient.getOrganizations(params);
51+
});
52+
it("should pass the path to the http client", () => {
53+
expect(mockClient.getLogs()[0].path).toBe("/api/v1/base/organizations");
54+
});
55+
it("should send a get request", () => {
56+
expect(mockClient.getLogs()[0].method).toBe("get");
57+
});
58+
it("should pass params as a param to the http client", () => {
59+
expect(mockClient.getLogs()[0].params).toEqual(params);
60+
});
61+
});
4262
});

0 commit comments

Comments
 (0)