Skip to content

Commit

Permalink
feat(rest-api-client): add plugin.getPlugins method
Browse files Browse the repository at this point in the history
  • Loading branch information
shabaraba committed Jul 25, 2024
1 parent e69fd16 commit db2e432
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/rest-api-client/src/KintoneRestAPIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AppClient } from "./client/AppClient";
import { RecordClient } from "./client/RecordClient";
import { SpaceClient } from "./client/SpaceClient";
import { FileClient } from "./client/FileClient";
import { PluginClient } from "./client/PluginClient";
import { DefaultHttpClient } from "./http/";
import type { ProxyConfig } from "./http/HttpClientInterface";
import type { BasicAuth, DiscriminatedAuth } from "./types/auth";
Expand Down Expand Up @@ -66,6 +67,7 @@ export class KintoneRestAPIClient {
app: AppClient;
space: SpaceClient;
file: FileClient;
plugin: PluginClient;
private bulkRequest_: BulkRequestClient;
private baseUrl?: string;

Expand Down Expand Up @@ -97,6 +99,7 @@ export class KintoneRestAPIClient {
this.app = new AppClient(httpClient, guestSpaceId);
this.space = new SpaceClient(httpClient, guestSpaceId);
this.file = new FileClient(httpClient, guestSpaceId);
this.plugin = new PluginClient(httpClient);
}

public static get version() {
Expand Down
11 changes: 11 additions & 0 deletions packages/rest-api-client/src/client/PluginClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { BaseClient } from "./BaseClient";
import type { GetPluginForRequest, GetPluginForResponse } from "./types/plugin";

export class PluginClient extends BaseClient {
public getPlugins(
params: GetPluginForRequest,
): Promise<GetPluginForResponse> {
const path = this.buildPath({ endpointName: "plugins" });
return this.client.get(path, params);
}
}
37 changes: 37 additions & 0 deletions packages/rest-api-client/src/client/__tests__/PluginClient.test.ts
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);
});
});
});
15 changes: 15 additions & 0 deletions packages/rest-api-client/src/client/types/plugin/index.ts
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 GetPluginForRequest = {
offset?: number;
limit?: number;
};

export type GetPluginForResponse = {
plugins: Plugin[];
};

0 comments on commit db2e432

Please sign in to comment.