|
| 1 | +// purposefully test COMPILED platform.js! (just as lambda_maker would) |
| 2 | +const { $sendConfigRuntimeTypeChecker } = require("../dist/platform") |
| 3 | + |
| 4 | +function randString() { |
| 5 | + return ""+Math.random() |
| 6 | +} |
| 7 | + |
| 8 | +const emptyConfig = {} |
| 9 | + |
| 10 | +// XXX would be nice to generate a lot of these tests automatically... |
| 11 | +// - should vary payload type (between string and object) |
| 12 | + |
| 13 | +describe("$send.email", () => { |
| 14 | + const checker = $sendConfigRuntimeTypeChecker.email |
| 15 | + let config |
| 16 | + beforeEach(() => { |
| 17 | + config = { |
| 18 | + html: randString(), |
| 19 | + subject: randString(), |
| 20 | + text: randString(), |
| 21 | + } |
| 22 | + }) |
| 23 | + |
| 24 | + it("should pass with empty config", () => { |
| 25 | + expect(() => checker(emptyConfig)).not.toThrow() |
| 26 | + }) |
| 27 | + |
| 28 | + it("should pass with full config", () => { |
| 29 | + expect(() => checker(config)).not.toThrow() |
| 30 | + }) |
| 31 | + |
| 32 | + xit("should fail with .__extra", () => { |
| 33 | + config.__extra = randString() |
| 34 | + expect(() => checker(config)).toThrow() |
| 35 | + }) |
| 36 | +}) |
| 37 | + |
| 38 | +describe("$send.http", () => { |
| 39 | + const checker = $sendConfigRuntimeTypeChecker.http |
| 40 | + let config |
| 41 | + beforeEach(() => { |
| 42 | + config = { |
| 43 | + method: randString(), |
| 44 | + url: randString(), |
| 45 | + auth: { |
| 46 | + password: randString(), |
| 47 | + username: randString(), |
| 48 | + }, |
| 49 | + data: randString(), |
| 50 | + headers: { |
| 51 | + [randString()]: randString(), |
| 52 | + [randString()]: randString(), |
| 53 | + }, |
| 54 | + params: { |
| 55 | + [randString()]: randString(), |
| 56 | + [randString()]: randString(), |
| 57 | + }, |
| 58 | + } |
| 59 | + }) |
| 60 | + |
| 61 | + it("should fail with empty config", () => { |
| 62 | + expect(() => checker({})).toThrow() |
| 63 | + }) |
| 64 | + |
| 65 | + it("should pass with full config", () => { |
| 66 | + expect(() => checker(config)).not.toThrow() |
| 67 | + }) |
| 68 | + |
| 69 | + xit("should fail with .__extra", () => { |
| 70 | + config.__extra = randString() |
| 71 | + expect(() => checker(config)).toThrow() |
| 72 | + }) |
| 73 | + |
| 74 | + it("should fail without .method", () => { |
| 75 | + delete config.method |
| 76 | + expect(() => checker(config)).toThrow() |
| 77 | + }) |
| 78 | + |
| 79 | + it("should fail without .url", () => { |
| 80 | + delete config.url |
| 81 | + expect(() => checker(config)).toThrow() |
| 82 | + }) |
| 83 | + |
| 84 | + it("should pass without .auth", () => { |
| 85 | + delete config.auth |
| 86 | + expect(() => checker(config)).not.toThrow() |
| 87 | + }) |
| 88 | + |
| 89 | + it("should fail without .auth.username", () => { |
| 90 | + delete config.auth.username |
| 91 | + expect(() => checker(config)).toThrow() |
| 92 | + }) |
| 93 | + |
| 94 | + it("should fail without .auth.password", () => { |
| 95 | + delete config.auth.password |
| 96 | + expect(() => checker(config)).toThrow() |
| 97 | + }) |
| 98 | + |
| 99 | + xit("should fail with .auth.__extra", () => { |
| 100 | + config.auth.__extra = randString() |
| 101 | + expect(() => checker(config)).toThrow() |
| 102 | + }) |
| 103 | + |
| 104 | + it("should pass without .data", () => { |
| 105 | + delete config.data |
| 106 | + expect(() => checker(config)).not.toThrow() |
| 107 | + }) |
| 108 | + |
| 109 | + it("should pass with object .data", () => { |
| 110 | + config.data = { |
| 111 | + [randString()]: randString(), |
| 112 | + [randString()]: randString(), |
| 113 | + } |
| 114 | + expect(() => checker(config)).not.toThrow() |
| 115 | + }) |
| 116 | + |
| 117 | + it("should pass without .headers", () => { |
| 118 | + delete config.headers |
| 119 | + expect(() => checker(config)).not.toThrow() |
| 120 | + }) |
| 121 | + |
| 122 | + it("should pass without .params", () => { |
| 123 | + delete config.params |
| 124 | + expect(() => checker(config)).not.toThrow() |
| 125 | + }) |
| 126 | +}) |
| 127 | + |
| 128 | +describe("$send.s3", () => { |
| 129 | + const checker = $sendConfigRuntimeTypeChecker.s3 |
| 130 | + let config |
| 131 | + beforeEach(() => { |
| 132 | + config = { |
| 133 | + bucket: randString(), |
| 134 | + payload: randString(), |
| 135 | + prefix: randString(), |
| 136 | + } |
| 137 | + }) |
| 138 | + |
| 139 | + it("should fail with empty config", () => { |
| 140 | + expect(() => checker({})).toThrow() |
| 141 | + }) |
| 142 | + |
| 143 | + it("should pass with full config", () => { |
| 144 | + expect(() => checker(config)).not.toThrow() |
| 145 | + }) |
| 146 | + |
| 147 | + xit("should fail with .__extra", () => { |
| 148 | + config.__extra = randString() |
| 149 | + expect(() => checker(config)).toThrow() |
| 150 | + }) |
| 151 | + |
| 152 | + it("should fail without .bucket", () => { |
| 153 | + delete config.bucket |
| 154 | + expect(() => checker(config)).toThrow() |
| 155 | + }) |
| 156 | + |
| 157 | + it("should fail without .payload", () => { |
| 158 | + delete config.payload |
| 159 | + expect(() => checker(config)).toThrow() |
| 160 | + }) |
| 161 | + |
| 162 | + it("should fail without .prefix", () => { |
| 163 | + delete config.prefix |
| 164 | + expect(() => checker(config)).toThrow() |
| 165 | + }) |
| 166 | +}) |
| 167 | + |
| 168 | +describe("$send.sql", () => { |
| 169 | + const checker = $sendConfigRuntimeTypeChecker.sql |
| 170 | + let config |
| 171 | + beforeEach(() => { |
| 172 | + config = { |
| 173 | + payload: randString(), |
| 174 | + table: randString(), |
| 175 | + } |
| 176 | + }) |
| 177 | + |
| 178 | + it("should fail with empty config", () => { |
| 179 | + expect(() => checker({})).toThrow() |
| 180 | + }) |
| 181 | + |
| 182 | + it("should pass with full config", () => { |
| 183 | + expect(() => checker(config)).not.toThrow() |
| 184 | + }) |
| 185 | + |
| 186 | + xit("should fail with .__extra", () => { |
| 187 | + config.__extra = randString() |
| 188 | + expect(() => checker(config)).toThrow() |
| 189 | + }) |
| 190 | + |
| 191 | + it("should fail without .payload", () => { |
| 192 | + delete config.payload |
| 193 | + expect(() => checker(config)).toThrow() |
| 194 | + }) |
| 195 | + |
| 196 | + it("should fail without .table", () => { |
| 197 | + delete config.table |
| 198 | + expect(() => checker(config)).toThrow() |
| 199 | + }) |
| 200 | +}) |
| 201 | + |
| 202 | +describe("$send.snowflake", () => { |
| 203 | + const checker = $sendConfigRuntimeTypeChecker.snowflake |
| 204 | + let config |
| 205 | + beforeEach(() => { |
| 206 | + config = { |
| 207 | + account: randString(), |
| 208 | + database: randString(), |
| 209 | + host: randString(), |
| 210 | + payload: randString(), |
| 211 | + pipe_name: randString(), |
| 212 | + private_key: randString(), |
| 213 | + schema: randString(), |
| 214 | + stage_name: randString(), |
| 215 | + user: randString(), |
| 216 | + } |
| 217 | + }) |
| 218 | + |
| 219 | + it("should fail with empty config", () => { |
| 220 | + expect(() => checker({})).toThrow() |
| 221 | + }) |
| 222 | + |
| 223 | + it("should pass with full config", () => { |
| 224 | + expect(() => checker(config)).not.toThrow() |
| 225 | + }) |
| 226 | + |
| 227 | + xit("should fail with .__extra", () => { |
| 228 | + config.__extra = randString() |
| 229 | + expect(() => checker(config)).toThrow() |
| 230 | + }) |
| 231 | + |
| 232 | + it("should fail without .account", () => { |
| 233 | + delete config.account |
| 234 | + expect(() => checker(config)).toThrow() |
| 235 | + }) |
| 236 | + |
| 237 | + it("should fail without .database", () => { |
| 238 | + delete config.database |
| 239 | + expect(() => checker(config)).toThrow() |
| 240 | + }) |
| 241 | + |
| 242 | + it("should fail without .host", () => { |
| 243 | + delete config.host |
| 244 | + expect(() => checker(config)).toThrow() |
| 245 | + }) |
| 246 | + |
| 247 | + it("should fail without .payload", () => { |
| 248 | + delete config.payload |
| 249 | + expect(() => checker(config)).toThrow() |
| 250 | + }) |
| 251 | + |
| 252 | + it("should fail without .pipe_name", () => { |
| 253 | + delete config.pipe_name |
| 254 | + expect(() => checker(config)).toThrow() |
| 255 | + }) |
| 256 | + |
| 257 | + it("should fail without .private_key", () => { |
| 258 | + delete config.private_key |
| 259 | + expect(() => checker(config)).toThrow() |
| 260 | + }) |
| 261 | + |
| 262 | + it("should fail without .schema", () => { |
| 263 | + delete config.schema |
| 264 | + expect(() => checker(config)).toThrow() |
| 265 | + }) |
| 266 | + |
| 267 | + it("should fail without .stage_name", () => { |
| 268 | + delete config.stage_name |
| 269 | + expect(() => checker(config)).toThrow() |
| 270 | + }) |
| 271 | + |
| 272 | + it("should fail without .user", () => { |
| 273 | + delete config.stage_name |
| 274 | + expect(() => checker(config)).toThrow() |
| 275 | + }) |
| 276 | +}) |
| 277 | + |
| 278 | +describe("$send.sse", () => { |
| 279 | + const checker = $sendConfigRuntimeTypeChecker.sse |
| 280 | + let config |
| 281 | + beforeEach(() => { |
| 282 | + config = { |
| 283 | + channel: randString(), |
| 284 | + payload: randString(), |
| 285 | + } |
| 286 | + }) |
| 287 | + |
| 288 | + it("should fail with empty config", () => { |
| 289 | + expect(() => checker({})).toThrow() |
| 290 | + }) |
| 291 | + |
| 292 | + it("should pass with full config", () => { |
| 293 | + expect(() => checker(config)).not.toThrow() |
| 294 | + }) |
| 295 | + |
| 296 | + xit("should fail with .__extra", () => { |
| 297 | + config.__extra = randString() |
| 298 | + expect(() => checker(config)).toThrow() |
| 299 | + }) |
| 300 | + |
| 301 | + it("should fail without .channel", () => { |
| 302 | + delete config.channel |
| 303 | + expect(() => checker(config)).toThrow() |
| 304 | + }) |
| 305 | + |
| 306 | + it("should fail without .payload", () => { |
| 307 | + delete config.payload |
| 308 | + expect(() => checker(config)).toThrow() |
| 309 | + }) |
| 310 | +}) |
0 commit comments