Skip to content

Commit

Permalink
Merge pull request #527 from betagouv/hotfix/send-slug-in-connect-url
Browse files Browse the repository at this point in the history
hotfix(js): use project slug in connect url
  • Loading branch information
wiwski authored Apr 19, 2023
2 parents 14bf146 + 8c1c93c commit 6cad63e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lab/templates/workplace/workplace.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<ul class="messagelist"></ul>
<div class="fr-grid-row fr-grid-row--right">
<button is="virtual-office-button"
project-name="{{ project.name }}"
project-slug="{{ project.slug }}"
class="fr-btn fr-icon-arrow-right-line fr-btn--icon-right">{% trans "Access virtual office" %}</button>
</div>
{% if user.is_lab_admin %}
Expand Down
14 changes: 7 additions & 7 deletions lab/workplace/assets/js/components/virtual-office-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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(
Expand Down Expand Up @@ -67,15 +67,15 @@ export default class VirtualOfficeButton extends HTMLButtonElement {

async initButton() {
const url = await euphrosyneToolsService.fetchVMConnectionLink(
this.projectName
this.projectSlug
);
if (url) {
this.connectionUrl = url;
this.disabled = false;
this.onConnectReady();
} else {
const deploymentStatus =
await euphrosyneToolsService.fetchDeploymentStatus(this.projectName);
await euphrosyneToolsService.fetchDeploymentStatus(this.projectSlug);
if (deploymentStatus) {
this.deploymentStatus = deploymentStatus;
if (deploymentStatus === "Failed") {
Expand All @@ -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;
Expand All @@ -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") {
Expand Down
28 changes: 14 additions & 14 deletions lab/workplace/assets/js/euphrosyne-tools-service.js
Original file line number Diff line number Diff line change
@@ -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",
}
Expand All @@ -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",
}
Expand All @@ -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",
}
Expand All @@ -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 }),
Expand Down
10 changes: 5 additions & 5 deletions lab/workplace/js_tests/components/virtual-office-button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -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);

Expand All @@ -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 {
Expand Down

0 comments on commit 6cad63e

Please sign in to comment.