|
| 1 | +import { it, expect, describe } from "bun:test"; |
| 2 | +import { |
| 3 | + runTerraformInit, |
| 4 | + testRequiredVariables, |
| 5 | + runTerraformApply, |
| 6 | +} from "../test"; |
| 7 | + |
| 8 | +describe("jetbrains", async () => { |
| 9 | + await runTerraformInit(import.meta.dir); |
| 10 | + |
| 11 | + await testRequiredVariables(import.meta.dir, { |
| 12 | + agent_id: "foo", |
| 13 | + folder: "/home/foo", |
| 14 | + }); |
| 15 | + |
| 16 | + it("should create a link with the default values", async () => { |
| 17 | + const state = await runTerraformApply(import.meta.dir, { |
| 18 | + // These are all required. |
| 19 | + agent_id: "foo", |
| 20 | + folder: "/home/coder", |
| 21 | + }); |
| 22 | + |
| 23 | + // Check that the URL contains the expected components |
| 24 | + const url = state.outputs.url.value; |
| 25 | + expect(url).toContain("jetbrains://gateway/com.coder.toolbox"); |
| 26 | + expect(url).toMatch(/workspace=[^&]+/); |
| 27 | + expect(url).toContain("owner=default"); |
| 28 | + expect(url).toContain("project_path=/home/coder"); |
| 29 | + expect(url).toContain("token=$SESSION_TOKEN"); |
| 30 | + expect(url).toContain("ide_product_code=CL"); // First option in the default list |
| 31 | + |
| 32 | + const coder_app = state.resources.find( |
| 33 | + (res) => res.type === "coder_app" && res.name === "jetbrains", |
| 34 | + ); |
| 35 | + |
| 36 | + expect(coder_app).not.toBeNull(); |
| 37 | + expect(coder_app?.instances.length).toBe(1); |
| 38 | + expect(coder_app?.instances[0].attributes.order).toBeNull(); |
| 39 | + }); |
| 40 | + |
| 41 | + it("should use the specified default IDE", async () => { |
| 42 | + const state = await runTerraformApply(import.meta.dir, { |
| 43 | + agent_id: "foo", |
| 44 | + folder: "/home/foo", |
| 45 | + default: "GO", |
| 46 | + }); |
| 47 | + expect(state.outputs.identifier.value).toBe("GO"); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should use the first IDE from options when no default is specified", async () => { |
| 51 | + const state = await runTerraformApply(import.meta.dir, { |
| 52 | + agent_id: "foo", |
| 53 | + folder: "/home/foo", |
| 54 | + options: '["PY", "GO", "IU"]', |
| 55 | + }); |
| 56 | + expect(state.outputs.identifier.value).toBe("PY"); |
| 57 | + }); |
| 58 | + |
| 59 | + it("should set the app order when specified", async () => { |
| 60 | + const state = await runTerraformApply(import.meta.dir, { |
| 61 | + agent_id: "foo", |
| 62 | + folder: "/home/foo", |
| 63 | + coder_app_order: 42, |
| 64 | + }); |
| 65 | + |
| 66 | + const coder_app = state.resources.find( |
| 67 | + (res) => res.type === "coder_app" && res.name === "jetbrains", |
| 68 | + ); |
| 69 | + |
| 70 | + expect(coder_app).not.toBeNull(); |
| 71 | + expect(coder_app?.instances[0].attributes.order).toBe(42); |
| 72 | + }); |
| 73 | + |
| 74 | + it("should use the latest build number when latest is true", async () => { |
| 75 | + const state = await runTerraformApply(import.meta.dir, { |
| 76 | + agent_id: "foo", |
| 77 | + folder: "/home/foo", |
| 78 | + latest: true, |
| 79 | + }); |
| 80 | + |
| 81 | + // We can't test the exact build number since it's fetched dynamically, |
| 82 | + // but we can check that the URL contains the build number parameter |
| 83 | + const url = state.outputs.url.value; |
| 84 | + expect(url).toContain("ide_build_number="); |
| 85 | + }); |
| 86 | +}); |
0 commit comments