|
3 | 3 | update_object,
|
4 | 4 | walk_and_store_blobs,
|
5 | 5 | skip_queue,
|
6 |
| - post_message |
| 6 | + post_message, |
| 7 | + handle_payload |
7 | 8 | } from "../helpers/data";
|
8 | 9 | import { NodeBlob } from "../client";
|
9 | 10 | import { config_response, endpoint_info } from "./test_data";
|
@@ -276,3 +277,135 @@ describe("post_message", () => {
|
276 | 277 | ]);
|
277 | 278 | });
|
278 | 279 | });
|
| 280 | + |
| 281 | +describe("handle_payload", () => { |
| 282 | + it("should return an input payload with null in place of `state` when with_null_state is true", () => { |
| 283 | + const resolved_payload = [2]; |
| 284 | + const dependency = { |
| 285 | + inputs: [1, 2] |
| 286 | + }; |
| 287 | + const components = [ |
| 288 | + { id: 1, type: "number" }, |
| 289 | + { id: 2, type: "state" } |
| 290 | + ]; |
| 291 | + const with_null_state = true; |
| 292 | + const result = handle_payload( |
| 293 | + resolved_payload, |
| 294 | + // @ts-ignore |
| 295 | + dependency, |
| 296 | + components, |
| 297 | + "input", |
| 298 | + with_null_state |
| 299 | + ); |
| 300 | + expect(result).toEqual([2, null]); |
| 301 | + }); |
| 302 | + it("should return an input payload with null in place of two `state` components when with_null_state is true", () => { |
| 303 | + const resolved_payload = ["hello", "goodbye"]; |
| 304 | + const dependency = { |
| 305 | + inputs: [1, 2, 3, 4] |
| 306 | + }; |
| 307 | + const components = [ |
| 308 | + { id: 1, type: "textbox" }, |
| 309 | + { id: 2, type: "state" }, |
| 310 | + { id: 3, type: "textbox" }, |
| 311 | + { id: 4, type: "state" } |
| 312 | + ]; |
| 313 | + const with_null_state = true; |
| 314 | + const result = handle_payload( |
| 315 | + resolved_payload, |
| 316 | + // @ts-ignore |
| 317 | + dependency, |
| 318 | + components, |
| 319 | + "input", |
| 320 | + with_null_state |
| 321 | + ); |
| 322 | + expect(result).toEqual(["hello", null, "goodbye", null]); |
| 323 | + }); |
| 324 | + |
| 325 | + it("should return an output payload without the state component value when with_null_state is false", () => { |
| 326 | + const resolved_payload = ["hello", null]; |
| 327 | + const dependency = { |
| 328 | + inputs: [2, 3] |
| 329 | + }; |
| 330 | + const components = [ |
| 331 | + { id: 2, type: "textbox" }, |
| 332 | + { id: 3, type: "state" } |
| 333 | + ]; |
| 334 | + const with_null_state = false; |
| 335 | + const result = handle_payload( |
| 336 | + resolved_payload, |
| 337 | + // @ts-ignore |
| 338 | + dependency, |
| 339 | + components, |
| 340 | + "output", |
| 341 | + with_null_state |
| 342 | + ); |
| 343 | + expect(result).toEqual(["hello"]); |
| 344 | + }); |
| 345 | + |
| 346 | + it("should return an ouput payload without the two state component values when with_null_state is false", () => { |
| 347 | + const resolved_payload = ["hello", null, "world", null]; |
| 348 | + const dependency = { |
| 349 | + inputs: [2, 3, 4, 5] |
| 350 | + }; |
| 351 | + const components = [ |
| 352 | + { id: 2, type: "textbox" }, |
| 353 | + { id: 3, type: "state" }, |
| 354 | + { id: 4, type: "textbox" }, |
| 355 | + { id: 5, type: "state" } |
| 356 | + ]; |
| 357 | + const with_null_state = false; |
| 358 | + const result = handle_payload( |
| 359 | + resolved_payload, |
| 360 | + // @ts-ignore |
| 361 | + dependency, |
| 362 | + components, |
| 363 | + "output", |
| 364 | + with_null_state |
| 365 | + ); |
| 366 | + expect(result).toEqual(["hello", "world"]); |
| 367 | + }); |
| 368 | + |
| 369 | + it("should return an ouput payload with the two state component values when with_null_state is true", () => { |
| 370 | + const resolved_payload = ["hello", null, "world", null]; |
| 371 | + const dependency = { |
| 372 | + inputs: [2, 3, 4, 5] |
| 373 | + }; |
| 374 | + const components = [ |
| 375 | + { id: 2, type: "textbox" }, |
| 376 | + { id: 3, type: "state" }, |
| 377 | + { id: 4, type: "textbox" }, |
| 378 | + { id: 5, type: "state" } |
| 379 | + ]; |
| 380 | + const with_null_state = true; |
| 381 | + const result = handle_payload( |
| 382 | + resolved_payload, |
| 383 | + // @ts-ignore |
| 384 | + dependency, |
| 385 | + components, |
| 386 | + "output", |
| 387 | + with_null_state |
| 388 | + ); |
| 389 | + expect(result).toEqual(["hello", null, "world", null]); |
| 390 | + }); |
| 391 | + |
| 392 | + it("should return the same payload where no state components are defined", () => { |
| 393 | + const resolved_payload = ["hello", "world"]; |
| 394 | + const dependency = { |
| 395 | + inputs: [2, 3] |
| 396 | + }; |
| 397 | + const components = [ |
| 398 | + { id: 2, type: "textbox" }, |
| 399 | + { id: 3, type: "textbox" } |
| 400 | + ]; |
| 401 | + const with_null_state = true; |
| 402 | + const result = handle_payload( |
| 403 | + resolved_payload, |
| 404 | + // @ts-ignore |
| 405 | + dependency, |
| 406 | + components, |
| 407 | + with_null_state |
| 408 | + ); |
| 409 | + expect(result).toEqual(["hello", "world"]); |
| 410 | + }); |
| 411 | +}); |
0 commit comments