@@ -2399,6 +2399,113 @@ describe("normalizeAndValidateConfig()", () => {
2399
2399
- \\"dispatch_namespaces[5]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"namespace\\":\\"DISPATCH_NAMESPACE_BINDING_SERVICE_1\\"}.
2400
2400
- \\"dispatch_namespaces[6]\\" should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456}.
2401
2401
- \\"dispatch_namespaces[6]\\" should have a string \\"namespace\\" field but got {\\"binding\\":123,\\"service\\":456}."
2402
+ ` ) ;
2403
+ } ) ;
2404
+
2405
+ test ( "should error on invalid outbounds for a namespace" , ( ) => {
2406
+ const { diagnostics } = normalizeAndValidateConfig (
2407
+ {
2408
+ dispatch_namespaces : [
2409
+ {
2410
+ binding : "DISPATCH_NAMESPACE_BINDING_1" ,
2411
+ namespace : "NAMESPACE" ,
2412
+ outbound : "a string" ,
2413
+ } ,
2414
+ {
2415
+ binding : "DISPATCH_NAMESPACE_BINDING_2" ,
2416
+ namespace : "NAMESPACE" ,
2417
+ outbound : [ { not : "valid" } ] ,
2418
+ } ,
2419
+ {
2420
+ binding : "DISPATCH_NAMESPACE_BINDING_3" ,
2421
+ namespace : "NAMESPACE" ,
2422
+ outbound : {
2423
+ service : 123 ,
2424
+ } ,
2425
+ } ,
2426
+ {
2427
+ binding : "DISPATCH_NAMESPACE_BINDING_4" ,
2428
+ namespace : "NAMESPACE" ,
2429
+ outbound : {
2430
+ service : "outbound" ,
2431
+ environment : { bad : "env" } ,
2432
+ } ,
2433
+ } ,
2434
+ {
2435
+ binding : "DISPATCH_NAMESPACE_BINDING_5" ,
2436
+ namespace : "NAMESPACE" ,
2437
+ outbound : {
2438
+ environment : "production" ,
2439
+ } ,
2440
+ } ,
2441
+ {
2442
+ binding : "DISPATCH_NAMESPACE_BINDING_6" ,
2443
+ namespace : "NAMESPACE" ,
2444
+ outbound : {
2445
+ service : "outbound" ,
2446
+ parameters : "bad" ,
2447
+ } ,
2448
+ } ,
2449
+ {
2450
+ binding : "DISPATCH_NAMESPACE_BINDING_7" ,
2451
+ namespace : "NAMESPACE" ,
2452
+ outbound : {
2453
+ service : "outbound" ,
2454
+ parameters : false ,
2455
+ } ,
2456
+ } ,
2457
+ {
2458
+ binding : "DISPATCH_NAMESPACE_BINDING_8" ,
2459
+ namespace : "NAMESPACE" ,
2460
+ outbound : {
2461
+ service : "outbound" ,
2462
+ parameters : [ true , { not : "good" } ] ,
2463
+ } ,
2464
+ } ,
2465
+ // these are correct
2466
+ {
2467
+ binding : "DISPATCH_NAMESPACE_BINDING_9" ,
2468
+ namespace : "NAMESPACE" ,
2469
+ outbound : {
2470
+ service : "outbound" ,
2471
+ parameters : [ "finally" , "real" , "params" ] ,
2472
+ } ,
2473
+ } ,
2474
+ {
2475
+ binding : "DISPATCH_NAMESPACE_BINDING_10" ,
2476
+ namespace : "NAMESPACE" ,
2477
+ outbound : {
2478
+ service : "outbound" ,
2479
+ environment : "production" ,
2480
+ parameters : [ "some" , "more" , "params" ] ,
2481
+ } ,
2482
+ } ,
2483
+ ] ,
2484
+ } as unknown as RawConfig ,
2485
+ undefined ,
2486
+ { env : undefined }
2487
+ ) ;
2488
+ expect ( diagnostics . hasWarnings ( ) ) . toBe ( false ) ;
2489
+ expect ( diagnostics . hasErrors ( ) ) . toBe ( true ) ;
2490
+ expect ( diagnostics . renderErrors ( ) ) . toMatchInlineSnapshot ( `
2491
+ "Processing wrangler configuration:
2492
+ - \\"dispatch_namespaces[0].outbound\\" should be an object, but got \\"a string\\"
2493
+ - \\"dispatch_namespaces[0]\\" has an invalid outbound definition.
2494
+ - \\"dispatch_namespaces[1].outbound.service\\" is a required field.
2495
+ - \\"dispatch_namespaces[1]\\" has an invalid outbound definition.
2496
+ - Expected \\"dispatch_namespaces[2].outbound.service\\" to be of type string but got 123.
2497
+ - \\"dispatch_namespaces[2]\\" has an invalid outbound definition.
2498
+ - Expected \\"dispatch_namespaces[3].outbound.environment\\" to be of type string but got {\\"bad\\":\\"env\\"}.
2499
+ - \\"dispatch_namespaces[3]\\" has an invalid outbound definition.
2500
+ - \\"dispatch_namespaces[4].outbound.service\\" is a required field.
2501
+ - \\"dispatch_namespaces[4]\\" has an invalid outbound definition.
2502
+ - Expected \\"dispatch_namespaces[5].outbound.parameters\\" to be an array of strings but got \\"bad\\"
2503
+ - \\"dispatch_namespaces[5]\\" has an invalid outbound definition.
2504
+ - Expected \\"dispatch_namespaces[6].outbound.parameters\\" to be an array of strings but got false
2505
+ - \\"dispatch_namespaces[6]\\" has an invalid outbound definition.
2506
+ - Expected \\"dispatch_namespaces[7].outbound.parameters.[0]\\" to be of type string but got true.
2507
+ - Expected \\"dispatch_namespaces[7].outbound.parameters.[1]\\" to be of type string but got {\\"not\\":\\"good\\"}.
2508
+ - \\"dispatch_namespaces[7]\\" has an invalid outbound definition."
2402
2509
` ) ;
2403
2510
} ) ;
2404
2511
} ) ;
0 commit comments