From e5025e25015a238f70b54d39b1919f7c00f87eed Mon Sep 17 00:00:00 2001 From: Panu Horsmalahti Date: Fri, 28 Jun 2024 09:20:24 +0300 Subject: [PATCH] feat: demo cluster api (#550) --- .github/workflows/dependabot-test.yaml | 2 +- .github/workflows/test.yaml | 2 +- integration-test/DemoClusterService.test.ts | 23 +++++++++++++++++++++ integration-test/TeamService.test.ts | 4 ++++ jest.integration-test.config.js | 2 +- src/DemoClusterService.ts | 23 +++++++++++++++++++++ src/LensPlatformClient.ts | 4 ++++ 7 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 integration-test/DemoClusterService.test.ts create mode 100644 src/DemoClusterService.ts diff --git a/.github/workflows/dependabot-test.yaml b/.github/workflows/dependabot-test.yaml index 7f78b5bf..21f24d76 100644 --- a/.github/workflows/dependabot-test.yaml +++ b/.github/workflows/dependabot-test.yaml @@ -30,7 +30,7 @@ jobs: TOKEN_HOST: ${{ secrets.TOKEN_HOST }} strategy: matrix: - node-version: [16] + node-version: [18] steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v3 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0eb60a98..db26dd86 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -32,7 +32,7 @@ jobs: max-parallel: 1 fail-fast: false matrix: - node-version: [16, 18] + node-version: [18] steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v3 diff --git a/integration-test/DemoClusterService.test.ts b/integration-test/DemoClusterService.test.ts new file mode 100644 index 00000000..82ec8c9d --- /dev/null +++ b/integration-test/DemoClusterService.test.ts @@ -0,0 +1,23 @@ +import { config } from "./configuration"; +import { testPlatformFactory } from "./utils"; +import type { TestPlatform } from "./utils"; + +jest.setTimeout(10000); + +describe("DemoClusterService", () => { + const [userBob] = config.users; + let bobPlatform: TestPlatform; + + beforeAll(async () => { + bobPlatform = await testPlatformFactory(userBob.username, userBob.password); + }); + + describe("getConfig", () => { + it("returns kubeconfig file", async () => { + const config = await bobPlatform.client.demoCluster.getConfig(); + + expect(config.startsWith("apiVersion: v1")).toBeTruthy(); + expect(typeof config).toBe("string"); + }); + }); +}); diff --git a/integration-test/TeamService.test.ts b/integration-test/TeamService.test.ts index 3e9f5481..59e044fb 100644 --- a/integration-test/TeamService.test.ts +++ b/integration-test/TeamService.test.ts @@ -37,6 +37,7 @@ describe("TeamService", () => { name: existingSpace.name, queryString: "join=teams", }); + teams = joinedSpace.teams as any as Team[]; }); @@ -48,6 +49,7 @@ describe("TeamService", () => { it("throws CantRemoveLastTeamUser if removing last user from Owner team", async () => { const ownerTeam = teams.find((team) => team.kind === "Owner"); + expect(ownerTeam).toBeTruthy(); return expect( @@ -60,6 +62,7 @@ describe("TeamService", () => { it("throws UserNameNotFoundException if removing user not in Team", async () => { const ownerTeam = teams.find((team) => team.kind === "Owner"); + expect(ownerTeam).toBeTruthy(); return expect( @@ -72,6 +75,7 @@ describe("TeamService", () => { it("throws ForbiddenException if removing user from another user", async () => { const ownerTeam = teams.find((team) => team.kind === "Owner"); + expect(ownerTeam).toBeTruthy(); return expect( diff --git a/jest.integration-test.config.js b/jest.integration-test.config.js index 8e53d35d..f6403890 100644 --- a/jest.integration-test.config.js +++ b/jest.integration-test.config.js @@ -4,7 +4,7 @@ const swcConfig = JSON.parse(fs.readFileSync(`${__dirname}/.test.swcrc`, "utf-8" module.exports = { globalSetup: `${__dirname}/integration-test/setup.ts`, moduleFileExtensions: ["js", "json", "ts"], - testPathIgnorePatterns: ["dist"], + testPathIgnorePatterns: ["src", "dist"], testRegex: ".*\\.test\\.ts$", transform: { "^.+\\.(t|j)sx?$": ["@swc/jest", swcConfig], diff --git a/src/DemoClusterService.ts b/src/DemoClusterService.ts new file mode 100644 index 00000000..4da293dc --- /dev/null +++ b/src/DemoClusterService.ts @@ -0,0 +1,23 @@ +import { Base } from "./Base"; +import { throwExpected } from "./exceptions"; + +type ConfigResponse = string; + +/** + * + * The class for consuming all `DemoCluster` resources. + * + */ +class DemoClusterService extends Base { + async getConfig(): Promise { + const { apiEndpointAddress, fetch } = this.lensPlatformClient; + const url = `${apiEndpointAddress}/demo-cluster/config`; + const response = await throwExpected(async () => fetch.get(url), { + unauthenticated: true, + } as any); + + return response as unknown as ConfigResponse; + } +} + +export { DemoClusterService }; diff --git a/src/LensPlatformClient.ts b/src/LensPlatformClient.ts index a9461b6a..3ae82288 100644 --- a/src/LensPlatformClient.ts +++ b/src/LensPlatformClient.ts @@ -15,6 +15,7 @@ import { UserRolesService } from "./UserRolesService"; import http from "http"; import https from "https"; import { LensDesktopKubeService } from "./LensDesktopKubeService"; +import { DemoClusterService } from "./DemoClusterService"; import { SSOService } from "./SSOService"; // Axios defaults to xhr adapter if XMLHttpRequest is available. @@ -130,6 +131,8 @@ class LensPlatformClient { lensDesktopKube: LensDesktopKubeService; + demoCluster: DemoClusterService; + space: SpaceService; roles: UserRolesService; @@ -182,6 +185,7 @@ class LensPlatformClient { this.user = new UserService(this); this.lensDesktopKube = new LensDesktopKubeService(this); + this.demoCluster = new DemoClusterService(this); this.space = new SpaceService(this); this.roles = new UserRolesService(this); this.team = new TeamService(this);