From 1bcf2a00730f5946b6d56739cf29f176f843b419 Mon Sep 17 00:00:00 2001 From: mustard Date: Fri, 22 Apr 2022 10:07:05 +0000 Subject: [PATCH] Fix ide not exists bug --- .../server/src/workspace/workspace-starter.spec.ts | 14 ++++++++++++++ .../server/src/workspace/workspace-starter.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/components/server/src/workspace/workspace-starter.spec.ts b/components/server/src/workspace/workspace-starter.spec.ts index 5161477e8fcf6d..12fd1b290361ae 100644 --- a/components/server/src/workspace/workspace-starter.spec.ts +++ b/components/server/src/workspace/workspace-starter.spec.ts @@ -249,5 +249,19 @@ describe("workspace-starter", function () { const result = chooseIDE("unknown-custom", customOptions, useLatest, hasPerm); expect(result.ideImage).to.equal(ideOptions.options["code"].latestImage); }); + + it("not exists ide with custom permission", function () { + const useLatest = true; + const hasPerm = true; + const result = chooseIDE("not-exists", ideOptions, useLatest, hasPerm); + expect(result.ideImage).to.equal(ideOptions.options["code"].latestImage); + }); + + it("not exists ide with custom permission", function () { + const useLatest = true; + const hasPerm = false; + const result = chooseIDE("not-exists", ideOptions, useLatest, hasPerm); + expect(result.ideImage).to.equal(ideOptions.options["code"].latestImage); + }); }); }); diff --git a/components/server/src/workspace/workspace-starter.ts b/components/server/src/workspace/workspace-starter.ts index 63ac46eb79fd01..21729c2a69b71e 100644 --- a/components/server/src/workspace/workspace-starter.ts +++ b/components/server/src/workspace/workspace-starter.ts @@ -156,7 +156,7 @@ export const chooseIDE = ( const data: { desktopIdeImage?: string; ideImage: string } = { ideImage: defaultIdeImage, }; - const chooseOption = ideOptions.options[ideChoice]; + const chooseOption = ideOptions.options[ideChoice] ?? defaultIDEOption; const isDesktopIde = chooseOption.type === "desktop"; if (isDesktopIde) { data.desktopIdeImage = useLatest ? chooseOption?.latestImage ?? chooseOption?.image : chooseOption?.image;