-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Base | ||
|
||
- [getUsers](#getusers) | ||
|
||
## Overview | ||
|
||
```ts | ||
const client = new GaroonRestAPIClient(); | ||
|
||
(async () => { | ||
try { | ||
console.log(await client.base.getUsers); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
})(); | ||
``` | ||
|
||
- All methods are defined on the `base` property. | ||
- This method returns a Promise object that is resolved with an object having properties in each `Returns` section. | ||
|
||
## Methods | ||
|
||
### getUsers | ||
|
||
Get users specified by conditions. | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Required | Description | | ||
| ------ | :----: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| limit | Number | | The number of users 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 users. | | ||
|
||
#### Returns | ||
|
||
See the example response in the `Reference`. | ||
|
||
#### Reference | ||
|
||
- https://developer.cybozu.io/hc/ja/articles/360018124651#step1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { HttpClient } from "../http"; | ||
import { buildPath } from "../url"; | ||
|
||
export class BaseClient { | ||
private readonly client: HttpClient; | ||
|
||
constructor(client: HttpClient) { | ||
this.client = client; | ||
} | ||
|
||
public getUsers(params?: { | ||
limit?: number; | ||
offset?: number; | ||
name?: string; | ||
}): Promise<{ | ||
users: Array<{ | ||
id: string; | ||
name: string; | ||
code: string; | ||
}>; | ||
}> { | ||
const path = buildPath({ endpointName: "base/users" }); | ||
return this.client.get(path, params ?? {}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { MockClient } from "../../http/MockClient"; | ||
import { GaroonRequestConfigBuilder } from "../../GaroonRequestConfigBuilder"; | ||
import { errorResponseHandler } from "../../GaroonRestAPIClient"; | ||
import { BaseClient } from "../BaseClient"; | ||
|
||
describe("BaseClient", () => { | ||
let mockClient: MockClient; | ||
let baseClient: BaseClient; | ||
|
||
beforeEach(() => { | ||
const requestConfigBuilder = new GaroonRequestConfigBuilder({ | ||
baseUrl: "https://example.cybozu.com/g", | ||
auth: { | ||
type: "password", | ||
username: "cybozu", | ||
password: "cybozu", | ||
}, | ||
}); | ||
mockClient = new MockClient({ requestConfigBuilder, errorResponseHandler }); | ||
baseClient = new BaseClient(mockClient); | ||
}); | ||
|
||
describe("getUsers", () => { | ||
const params = { | ||
limit: 100, | ||
offset: 0, | ||
name: "test", | ||
}; | ||
beforeEach(async () => { | ||
await baseClient.getUsers(params); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe("/api/v1/base/users"); | ||
}); | ||
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); | ||
}); | ||
}); | ||
}); |