|
1 | | -import { workspace } from "vscode"; |
| 1 | +import { ConfigurationTarget, workspace } from "vscode"; |
2 | 2 |
|
3 | 3 | import type { ConfigListener } from "../../../src/config"; |
4 | 4 | import { |
5 | 5 | CliConfigListener, |
6 | 6 | QueryHistoryConfigListener, |
7 | 7 | QueryServerConfigListener, |
| 8 | + VSCODE_GITHUB_ENTERPRISE_URI_SETTING, |
| 9 | + getEnterpriseUri, |
| 10 | + hasEnterpriseUri, |
| 11 | + hasGhecDrUri, |
8 | 12 | } from "../../../src/config"; |
9 | 13 | import { vscodeGetConfigurationMock } from "../test-config"; |
10 | 14 |
|
@@ -126,3 +130,49 @@ describe("config listeners", () => { |
126 | 130 | return new Promise((resolve) => setTimeout(resolve, ms)); |
127 | 131 | } |
128 | 132 | }); |
| 133 | + |
| 134 | +describe("enterprise URI", () => { |
| 135 | + it("detects no enterprise URI when config value is not set", async () => { |
| 136 | + expect(getEnterpriseUri()).toBeUndefined(); |
| 137 | + expect(hasEnterpriseUri()).toBe(false); |
| 138 | + expect(hasGhecDrUri()).toBe(false); |
| 139 | + }); |
| 140 | + |
| 141 | + it("detects no enterprise URI when config value is set to an invalid value", async () => { |
| 142 | + await VSCODE_GITHUB_ENTERPRISE_URI_SETTING.updateValue( |
| 143 | + "invalid-uri", |
| 144 | + ConfigurationTarget.Global, |
| 145 | + ); |
| 146 | + expect(getEnterpriseUri()).toBeUndefined(); |
| 147 | + expect(hasEnterpriseUri()).toBe(false); |
| 148 | + expect(hasGhecDrUri()).toBe(false); |
| 149 | + }); |
| 150 | + |
| 151 | + it("detects an enterprise URI when config value is set to a GHES URI", async () => { |
| 152 | + await VSCODE_GITHUB_ENTERPRISE_URI_SETTING.updateValue( |
| 153 | + "https://github.example.com", |
| 154 | + ConfigurationTarget.Global, |
| 155 | + ); |
| 156 | + expect(getEnterpriseUri()?.toString()).toBe("https://github.example.com/"); |
| 157 | + expect(hasEnterpriseUri()).toBe(true); |
| 158 | + expect(hasGhecDrUri()).toBe(false); |
| 159 | + }); |
| 160 | + |
| 161 | + it("detects a GHEC-DR URI when config value is set to a GHEC-DR URI", async () => { |
| 162 | + await VSCODE_GITHUB_ENTERPRISE_URI_SETTING.updateValue( |
| 163 | + "https://example.ghe.com", |
| 164 | + ConfigurationTarget.Global, |
| 165 | + ); |
| 166 | + expect(getEnterpriseUri()?.toString()).toBe("https://example.ghe.com/"); |
| 167 | + expect(hasEnterpriseUri()).toBe(true); |
| 168 | + expect(hasGhecDrUri()).toBe(true); |
| 169 | + }); |
| 170 | + |
| 171 | + it("Upgrades HTTP URIs to HTTPS", async () => { |
| 172 | + await VSCODE_GITHUB_ENTERPRISE_URI_SETTING.updateValue( |
| 173 | + "http://example.ghe.com", |
| 174 | + ConfigurationTarget.Global, |
| 175 | + ); |
| 176 | + expect(getEnterpriseUri()?.toString()).toBe("https://example.ghe.com/"); |
| 177 | + }); |
| 178 | +}); |
0 commit comments