-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rest-api-client): add plugin.getPlugins method
- Loading branch information
Showing
4 changed files
with
69 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
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,14 @@ | ||
import { BaseClient } from "./BaseClient"; | ||
import type { | ||
GetPluginsForRequest, | ||
GetPluginsForResponse, | ||
} from "./types/plugin"; | ||
|
||
export class PluginClient extends BaseClient { | ||
public getPlugins( | ||
params: GetPluginsForRequest, | ||
): Promise<GetPluginsForResponse> { | ||
const path = this.buildPath({ endpointName: "plugins" }); | ||
return this.client.get(path, params); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/rest-api-client/src/client/__tests__/PluginClient.test.ts
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,37 @@ | ||
import type { MockClient } from "../../http/MockClient"; | ||
import { buildMockClient } from "../../http/MockClient"; | ||
import { KintoneRequestConfigBuilder } from "../../KintoneRequestConfigBuilder"; | ||
import { PluginClient } from "../PluginClient"; | ||
|
||
describe("PluginClient", () => { | ||
let mockClient: MockClient; | ||
let pluginClient: PluginClient; | ||
|
||
beforeEach(() => { | ||
const requestConfigBuilder = new KintoneRequestConfigBuilder({ | ||
baseUrl: "https://example.cybozu.com", | ||
auth: { type: "apiToken", apiToken: "foo" }, | ||
}); | ||
mockClient = buildMockClient(requestConfigBuilder); | ||
pluginClient = new PluginClient(mockClient); | ||
}); | ||
|
||
describe("getPlugins", () => { | ||
const params = { | ||
offset: 1, | ||
limit: 2, | ||
}; | ||
beforeEach(async () => { | ||
await pluginClient.getPlugins(params); | ||
}); | ||
it("should pass the path to the http client", () => { | ||
expect(mockClient.getLogs()[0].path).toBe("/k/v1/plugins.json"); | ||
}); | ||
it("should send a GET request", () => { | ||
expect(mockClient.getLogs()[0].method).toBe("get"); | ||
}); | ||
it("should pass the param to the http client", () => { | ||
expect(mockClient.getLogs()[0].params).toEqual(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,15 @@ | ||
type Plugin = { | ||
id: string; | ||
name: string; | ||
isMarketPlugin: boolean; | ||
revision: string; | ||
}; | ||
|
||
export type GetPluginsForRequest = { | ||
offset?: number; | ||
limit?: number; | ||
}; | ||
|
||
export type GetPluginsForResponse = { | ||
plugins: Plugin[]; | ||
}; |