From 8c1c93cc9314c9dedca114ee54a7b5c486c74c8c Mon Sep 17 00:00:00 2001 From: witold Date: Wed, 19 Apr 2023 18:07:07 +0200 Subject: [PATCH] hotfix(js): use project slug in connect url --- lab/templates/workplace/workplace.html | 2 +- .../js/components/virtual-office-button.js | 14 +++++----- .../assets/js/euphrosyne-tools-service.js | 28 +++++++++---------- .../components/virtual-office-button.spec.js | 10 +++---- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lab/templates/workplace/workplace.html b/lab/templates/workplace/workplace.html index 225eac5e3..d7876db2a 100644 --- a/lab/templates/workplace/workplace.html +++ b/lab/templates/workplace/workplace.html @@ -21,7 +21,7 @@
{% if user.is_lab_admin %} diff --git a/lab/workplace/assets/js/components/virtual-office-button.js b/lab/workplace/assets/js/components/virtual-office-button.js index 76f1f9c19..64954ca40 100644 --- a/lab/workplace/assets/js/components/virtual-office-button.js +++ b/lab/workplace/assets/js/components/virtual-office-button.js @@ -10,8 +10,8 @@ export default class VirtualOfficeButton extends HTMLButtonElement { }); } - get projectName() { - return this.getAttribute("project-name"); + get projectSlug() { + return this.getAttribute("project-slug"); } constructor() { @@ -35,7 +35,7 @@ export default class VirtualOfficeButton extends HTMLButtonElement { } else { this.disabled = true; try { - await euphrosyneToolsService.deployVM(this.projectName); + await euphrosyneToolsService.deployVM(this.projectSlug); } catch (error) { this.disabled = false; utils.displayMessage( @@ -67,7 +67,7 @@ export default class VirtualOfficeButton extends HTMLButtonElement { async initButton() { const url = await euphrosyneToolsService.fetchVMConnectionLink( - this.projectName + this.projectSlug ); if (url) { this.connectionUrl = url; @@ -75,7 +75,7 @@ export default class VirtualOfficeButton extends HTMLButtonElement { this.onConnectReady(); } else { const deploymentStatus = - await euphrosyneToolsService.fetchDeploymentStatus(this.projectName); + await euphrosyneToolsService.fetchDeploymentStatus(this.projectSlug); if (deploymentStatus) { this.deploymentStatus = deploymentStatus; if (deploymentStatus === "Failed") { @@ -93,7 +93,7 @@ export default class VirtualOfficeButton extends HTMLButtonElement { async checkDeploymentProgress() { if (this.deploymentStatus && this.deploymentStatus === "Succeeded") { const url = await euphrosyneToolsService.fetchVMConnectionLink( - this.projectName + this.projectSlug ); if (url) { this.connectionUrl = url; @@ -111,7 +111,7 @@ export default class VirtualOfficeButton extends HTMLButtonElement { } } else { const deploymentStatus = - await euphrosyneToolsService.fetchDeploymentStatus(this.projectName); + await euphrosyneToolsService.fetchDeploymentStatus(this.projectSlug); if (deploymentStatus) { this.deploymentStatus = deploymentStatus; if (this.deploymentStatus === "Failed") { diff --git a/lab/workplace/assets/js/euphrosyne-tools-service.js b/lab/workplace/assets/js/euphrosyne-tools-service.js index ab8eb628b..85f140712 100644 --- a/lab/workplace/assets/js/euphrosyne-tools-service.js +++ b/lab/workplace/assets/js/euphrosyne-tools-service.js @@ -1,8 +1,8 @@ import { jwtFetch } from "../../../assets/js/jwt.js"; -async function fetchVMConnectionLink(projectName) { +async function fetchVMConnectionLink(projectSlug) { const response = await jwtFetch( - `${process.env.EUPHROSYNE_TOOLS_API_URL}/connect/${projectName}`, + `${process.env.EUPHROSYNE_TOOLS_API_URL}/connect/${projectSlug}`, { method: "GET", } @@ -12,12 +12,12 @@ async function fetchVMConnectionLink(projectName) { } else if (response.status === 404) { return null; } - throw new Error(`An error occured while fetching project ${projectName} VM`); + throw new Error(`An error occured while fetching project ${projectSlug} VM`); } -async function fetchDeploymentStatus(projectName) { +async function fetchDeploymentStatus(projectSlug) { const response = await jwtFetch( - `${process.env.EUPHROSYNE_TOOLS_API_URL}/deployments/${projectName}`, + `${process.env.EUPHROSYNE_TOOLS_API_URL}/deployments/${projectSlug}`, { method: "GET", } @@ -28,31 +28,31 @@ async function fetchDeploymentStatus(projectName) { return null; } throw new Error( - `An error occured while fetching project ${projectName} deployment status` + `An error occured while fetching project ${projectSlug} deployment status` ); } -function deployVM(projectName) { +function deployVM(projectSlug) { return jwtFetch( - `${process.env.EUPHROSYNE_TOOLS_API_URL}/deployments/${projectName}`, + `${process.env.EUPHROSYNE_TOOLS_API_URL}/deployments/${projectSlug}`, { method: "POST", } ); } -function deleteVM(projectName) { +function deleteVM(projectSlug) { return jwtFetch( - `${process.env.EUPHROSYNE_TOOLS_API_URL}/vms/${projectName}`, + `${process.env.EUPHROSYNE_TOOLS_API_URL}/vms/${projectSlug}`, { method: "DELETE", } ); } -async function fetchProjectVmSize(projectName) { +async function fetchProjectVmSize(projectSlug) { const response = await jwtFetch( - `${process.env.EUPHROSYNE_TOOLS_API_URL}/config/${projectName}/vm-size`, + `${process.env.EUPHROSYNE_TOOLS_API_URL}/config/${projectSlug}/vm-size`, { method: "GET", } @@ -62,9 +62,9 @@ async function fetchProjectVmSize(projectName) { } } -async function setProjectVmSize(projectName, vmSize) { +async function setProjectVmSize(projectSlug, vmSize) { return jwtFetch( - `${process.env.EUPHROSYNE_TOOLS_API_URL}/config/${projectName}/vm-size`, + `${process.env.EUPHROSYNE_TOOLS_API_URL}/config/${projectSlug}/vm-size`, { method: "POST", body: JSON.stringify({ vm_size: vmSize }), diff --git a/lab/workplace/js_tests/components/virtual-office-button.spec.js b/lab/workplace/js_tests/components/virtual-office-button.spec.js index 494b9bdb4..4a1ec6286 100644 --- a/lab/workplace/js_tests/components/virtual-office-button.spec.js +++ b/lab/workplace/js_tests/components/virtual-office-button.spec.js @@ -27,12 +27,12 @@ describe("Test VirtualOfficeButton", () => { describe("Button init", () => { describe("When receiving connection URL directly", () => { beforeEach(() => { - voButton.setAttribute("project-name", "projet tango"); + voButton.setAttribute("project-slug", "projet-tango"); fetchVMMock.mockResolvedValueOnce("url"); }); it("creates the button properly", async () => { await voButton.initButton(); - expect(voButton.projectName).toBe("projet tango"); + expect(voButton.projectSlug).toBe("projet-tango"); expect(voButton.connectionUrl).toBe("url"); expect(voButton.disabled).toBeFalsy(); }); @@ -121,10 +121,10 @@ describe("Test VirtualOfficeButton", () => { const waitDeployMock = jest .spyOn(VirtualOfficeButton.prototype, "waitForDeploymentComplete") .mockImplementationOnce(() => {}); - voButton.setAttribute("project-name", "projet tango"); + voButton.setAttribute("project-slug", "projet-tango"); await voButton.onButtonClick(); - expect(deployMock).toHaveBeenCalledWith("projet tango"); + expect(deployMock).toHaveBeenCalledWith("projet-tango"); expect(waitDeployMock).toHaveBeenCalledTimes(1); expect(voButton.disabled).toBe(true); @@ -135,7 +135,7 @@ describe("Test VirtualOfficeButton", () => { const deployMock = jest .spyOn(euphrosyneToolsService, "deployVM") .mockImplementationOnce(() => Promise.reject()); - voButton.setAttribute("project-name", "projet tango"); + voButton.setAttribute("project-slug", "projet-tango"); let hadError = false; try {