Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rest-api-client): add app.moveToSpace method #2855

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/rest-api-client-demo/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,4 +764,14 @@ export class App {
console.log(error);
}
}

public async moveToSpace() {
try {
console.log(
await this.client.app.moveToSpace({ app: APP_ID, space: SPACE_ID }),
);
} catch (error) {
console.log(error);
}
}
}
20 changes: 20 additions & 0 deletions packages/rest-api-client/docs/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- [updateReports](#updateReports)
- [getAppActions](#getAppActions)
- [updateAppActions](#updateAppActions)
- [moveToSpace](#moveToSpace)

## Overview

Expand Down Expand Up @@ -1353,3 +1354,22 @@ Updates the [Action](https://get.kintone.help/k/en/user/app_settings/appaction/s
#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/apps/update-action-settings/

### moveToSpace

Changes the Space to which an App belongs.

#### Parameters

| Name | Type | Required | Description |
| ----- | :----------------------: | :------: | ----------------------------------------------------------------------------------------------------------------------- |
| app | Number or String | Yes | The App ID. |
| space | Number or String or null | Yes | The Space ID of where the App will be moved to. <br />To remove an App from its current space, `null` can be specified. |

#### Returns

An empty object.

#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/apps/move-app-to-space/
11 changes: 11 additions & 0 deletions packages/rest-api-client/src/client/AppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {
ReportForResponse,
AppActionsForParameter,
AppActionsForResponse,
SpaceID,
} from "./types";
import { BaseClient } from "./BaseClient";
type RowLayoutForParameter = {
Expand Down Expand Up @@ -616,4 +617,14 @@ export class AppClient extends BaseClient {
});
return this.client.put(path, params);
}

public moveToSpace(params: {
app: AppID;
space: SpaceID | null;
}): Promise<{}> {
const path = this.buildPath({
endpointName: "app/move",
});
return this.client.post(path, params);
}
}
31 changes: 31 additions & 0 deletions packages/rest-api-client/src/client/__tests__/AppClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,37 @@ describe("AppClient", () => {
});
});

describe("AppClient: moveToSpace", () => {
let mockClient: MockClient;
let appClient: AppClient;

beforeEach(() => {
const requestConfigBuilder = new KintoneRequestConfigBuilder({
baseUrl: "https://example.cybozu.com",
auth: { type: "apiToken", apiToken: "foo" },
});
mockClient = buildMockClient(requestConfigBuilder);
appClient = new AppClient(mockClient);
});
describe("moveToSpace", () => {
const params = { app: APP_ID, space: 1 } as const;
describe("without preview", () => {
beforeEach(async () => {
await appClient.moveToSpace(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/k/v1/app/move.json");
});
it("should send a post request", () => {
expect(mockClient.getLogs()[0].method).toBe("post");
});
it("should pass app and space as a param to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});
});
});

describe("AppClient with guestSpaceId", () => {
it("should pass the path to the http client", async () => {
const GUEST_SPACE_ID = 2;
Expand Down