|
1 | 1 | import { describe, expect, it } from "@jest/globals"; |
2 | 2 | import { configPage, configVar, flow } from ".."; |
3 | | -import { convertConfigPages, convertFlow } from "./convertIntegration"; |
| 3 | +import { convertConfigPages, convertFlow, convertConfigVar } from "./convertIntegration"; |
| 4 | +import type { ConfigVar } from "../types"; |
4 | 5 |
|
5 | 6 | describe("convertFlow with polling triggers", () => { |
6 | 7 | const baseFlowInput = { |
@@ -146,3 +147,132 @@ describe("convertConfigPages", () => { |
146 | 147 | expect(result[0].elements).toHaveLength(0); |
147 | 148 | }); |
148 | 149 | }); |
| 150 | + |
| 151 | +describe("convertConfigVar", () => { |
| 152 | + const referenceKey = "test-component"; |
| 153 | + const componentRegistry = {}; |
| 154 | + |
| 155 | + describe("onPremConnectionConfig validation", () => { |
| 156 | + it("should return onPremiseConnectionConfig when connection has onPremControlled inputs and config set", () => { |
| 157 | + const connectionConfigVar = { |
| 158 | + stableKey: "test-connection", |
| 159 | + dataType: "connection", |
| 160 | + onPremConnectionConfig: "allowed", |
| 161 | + inputs: { |
| 162 | + host: { |
| 163 | + label: "Host", |
| 164 | + type: "string", |
| 165 | + onPremControlled: true, |
| 166 | + }, |
| 167 | + port: { |
| 168 | + label: "Port", |
| 169 | + type: "string", |
| 170 | + onPremControlled: true, |
| 171 | + }, |
| 172 | + }, |
| 173 | + } as ConfigVar; |
| 174 | + |
| 175 | + const result = convertConfigVar( |
| 176 | + "TestConnection", |
| 177 | + connectionConfigVar, |
| 178 | + referenceKey, |
| 179 | + componentRegistry, |
| 180 | + ); |
| 181 | + expect("onPremiseConnectionConfig" in result && result.onPremiseConnectionConfig).toBe( |
| 182 | + "allowed", |
| 183 | + ); |
| 184 | + }); |
| 185 | + |
| 186 | + it("should throw when connection has onPremControlled inputs but no onPremConnectionConfig", () => { |
| 187 | + const connectionConfigVar = { |
| 188 | + stableKey: "test-connection", |
| 189 | + dataType: "connection", |
| 190 | + inputs: { |
| 191 | + host: { |
| 192 | + label: "Host", |
| 193 | + type: "string", |
| 194 | + onPremControlled: true, |
| 195 | + }, |
| 196 | + port: { |
| 197 | + label: "Port", |
| 198 | + type: "string", |
| 199 | + onPremControlled: true, |
| 200 | + }, |
| 201 | + }, |
| 202 | + } as ConfigVar; |
| 203 | + |
| 204 | + expect(() => |
| 205 | + convertConfigVar("TestConnection", connectionConfigVar, referenceKey, componentRegistry), |
| 206 | + ).toThrow( |
| 207 | + "Connection test-connection has onPremControlled inputs but no onPremConnectionConfig value set", |
| 208 | + ); |
| 209 | + }); |
| 210 | + |
| 211 | + it("should default to 'disallowed' when connection has no onPremControlled inputs and no config", () => { |
| 212 | + const connectionConfigVar = { |
| 213 | + stableKey: "test-connection", |
| 214 | + dataType: "connection", |
| 215 | + inputs: { |
| 216 | + apiKey: { |
| 217 | + label: "API Key", |
| 218 | + type: "string", |
| 219 | + }, |
| 220 | + }, |
| 221 | + } as ConfigVar; |
| 222 | + |
| 223 | + const result = convertConfigVar( |
| 224 | + "TestConnection", |
| 225 | + connectionConfigVar, |
| 226 | + referenceKey, |
| 227 | + componentRegistry, |
| 228 | + ); |
| 229 | + expect("onPremiseConnectionConfig" in result && result.onPremiseConnectionConfig).toBe( |
| 230 | + "disallowed", |
| 231 | + ); |
| 232 | + }); |
| 233 | + |
| 234 | + it("should allow 'disallowed' config when connection has no onPremControlled inputs", () => { |
| 235 | + const connectionConfigVar = { |
| 236 | + stableKey: "test-connection", |
| 237 | + dataType: "connection", |
| 238 | + onPremConnectionConfig: "disallowed", |
| 239 | + inputs: { |
| 240 | + apiKey: { |
| 241 | + label: "API Key", |
| 242 | + type: "string", |
| 243 | + }, |
| 244 | + }, |
| 245 | + } as ConfigVar; |
| 246 | + |
| 247 | + const result = convertConfigVar( |
| 248 | + "TestConnection", |
| 249 | + connectionConfigVar, |
| 250 | + referenceKey, |
| 251 | + componentRegistry, |
| 252 | + ); |
| 253 | + expect("onPremiseConnectionConfig" in result && result.onPremiseConnectionConfig).toBe( |
| 254 | + "disallowed", |
| 255 | + ); |
| 256 | + }); |
| 257 | + |
| 258 | + it("should throw when connection has defined config but no onPremControlled inputs", () => { |
| 259 | + const connectionConfigVar = { |
| 260 | + stableKey: "test-connection", |
| 261 | + dataType: "connection", |
| 262 | + onPremConnectionConfig: "allowed", |
| 263 | + inputs: { |
| 264 | + apiKey: { |
| 265 | + label: "API Key", |
| 266 | + type: "string", |
| 267 | + }, |
| 268 | + }, |
| 269 | + } as ConfigVar; |
| 270 | + |
| 271 | + expect(() => |
| 272 | + convertConfigVar("TestConnection", connectionConfigVar, referenceKey, componentRegistry), |
| 273 | + ).toThrow( |
| 274 | + "Connection test-connection has onPremConnectionConfig set but no onPremControlled inputs", |
| 275 | + ); |
| 276 | + }); |
| 277 | + }); |
| 278 | +}); |
0 commit comments