Skip to content

Commit

Permalink
feat: demo cluster api (#550) (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
panuhorsmalahti authored Jun 28, 2024
1 parent 973b667 commit 6519dbc
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions integration-test/DemoClusterService.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
});
4 changes: 4 additions & 0 deletions integration-test/TeamService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("TeamService", () => {
name: existingSpace.name,
queryString: "join=teams",
});

teams = joinedSpace.teams as any as Team[];
});

Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion jest.integration-test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
23 changes: 23 additions & 0 deletions src/DemoClusterService.ts
Original file line number Diff line number Diff line change
@@ -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<ConfigResponse> {
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 };
4 changes: 4 additions & 0 deletions src/LensPlatformClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -130,6 +131,8 @@ class LensPlatformClient {

lensDesktopKube: LensDesktopKubeService;

demoCluster: DemoClusterService;

space: SpaceService;

roles: UserRolesService;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6519dbc

Please sign in to comment.