|
| 1 | +import { describe, expect, it } from "bun:test"; |
| 2 | +import { |
| 3 | + runTerraformApply, |
| 4 | + runTerraformInit, |
| 5 | + testRequiredVariables, |
| 6 | +} from "~test"; |
| 7 | + |
| 8 | +// hardcoded coder_app name in main.tf |
| 9 | +const appName = "vscode-desktop"; |
| 10 | + |
| 11 | +const defaultVariables = { |
| 12 | + agent_id: "foo", |
| 13 | + coder_app_icon: "/icon/code.svg", |
| 14 | + coder_app_slug: "vscode", |
| 15 | + coder_app_display_name: "VS Code Desktop", |
| 16 | + protocol: "vscode", |
| 17 | +} |
| 18 | + |
| 19 | +describe("vscode-desktop-core", async () => { |
| 20 | + await runTerraformInit(import.meta.dir); |
| 21 | + |
| 22 | + testRequiredVariables(import.meta.dir, defaultVariables); |
| 23 | + |
| 24 | + it("default output", async () => { |
| 25 | + const state = await runTerraformApply(import.meta.dir, defaultVariables); |
| 26 | + expect(state.outputs.ide_uri.value).toBe( |
| 27 | + `${defaultVariables.protocol}://coder.coder-remote/open?owner=default&workspace=default&url=https://mydeployment.coder.com&token=$SESSION_TOKEN`, |
| 28 | + ); |
| 29 | + |
| 30 | + const coder_app = state.resources.find( |
| 31 | + (res) => res.type === "coder_app" && res.name === appName, |
| 32 | + ); |
| 33 | + |
| 34 | + expect(coder_app).not.toBeNull(); |
| 35 | + expect(coder_app?.instances.length).toBe(1); |
| 36 | + expect(coder_app?.instances[0].attributes.order).toBeNull(); |
| 37 | + }); |
| 38 | + |
| 39 | + it("adds folder", async () => { |
| 40 | + const state = await runTerraformApply(import.meta.dir, { |
| 41 | + folder: "/foo/bar", |
| 42 | + |
| 43 | + ...defaultVariables |
| 44 | + }); |
| 45 | + |
| 46 | + expect(state.outputs.ide_uri.value).toBe( |
| 47 | + `${defaultVariables.protocol}://coder.coder-remote/open?owner=default&workspace=default&folder=/foo/bar&url=https://mydeployment.coder.com&token=$SESSION_TOKEN`, |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + it("adds folder and open_recent", async () => { |
| 52 | + const state = await runTerraformApply(import.meta.dir, { |
| 53 | + folder: "/foo/bar", |
| 54 | + open_recent: "true", |
| 55 | + |
| 56 | + ...defaultVariables, |
| 57 | + }); |
| 58 | + expect(state.outputs.ide_uri.value).toBe( |
| 59 | + `${defaultVariables.protocol}://coder.coder-remote/open?owner=default&workspace=default&folder=/foo/bar&openRecent&url=https://mydeployment.coder.com&token=$SESSION_TOKEN`, |
| 60 | + ); |
| 61 | + }); |
| 62 | + |
| 63 | + it("adds folder but not open_recent", async () => { |
| 64 | + const state = await runTerraformApply(import.meta.dir, { |
| 65 | + folder: "/foo/bar", |
| 66 | + openRecent: "false", |
| 67 | + |
| 68 | + ...defaultVariables, |
| 69 | + }); |
| 70 | + expect(state.outputs.ide_uri.value).toBe( |
| 71 | + `${defaultVariables.protocol}://coder.coder-remote/open?owner=default&workspace=default&folder=/foo/bar&url=https://mydeployment.coder.com&token=$SESSION_TOKEN`, |
| 72 | + ); |
| 73 | + }); |
| 74 | + |
| 75 | + it("adds open_recent", async () => { |
| 76 | + const state = await runTerraformApply(import.meta.dir, { |
| 77 | + open_recent: "true", |
| 78 | + |
| 79 | + ...defaultVariables, |
| 80 | + }); |
| 81 | + expect(state.outputs.ide_uri.value).toBe( |
| 82 | + `${defaultVariables.protocol}://coder.coder-remote/open?owner=default&workspace=default&openRecent&url=https://mydeployment.coder.com&token=$SESSION_TOKEN`, |
| 83 | + ); |
| 84 | + }); |
| 85 | + |
| 86 | + it("expect order to be set", async () => { |
| 87 | + const state = await runTerraformApply(import.meta.dir, { |
| 88 | + coder_app_order: "22", |
| 89 | + ...defaultVariables |
| 90 | + }); |
| 91 | + |
| 92 | + const coder_app = state.resources.find( |
| 93 | + (res) => res.type === "coder_app" && res.name === appName, |
| 94 | + ); |
| 95 | + |
| 96 | + expect(coder_app).not.toBeNull(); |
| 97 | + expect(coder_app?.instances.length).toBe(1); |
| 98 | + expect(coder_app?.instances[0].attributes.order).toBe(22); |
| 99 | + }); |
| 100 | +}); |
0 commit comments