@@ -4,6 +4,7 @@ import test from "node:test";
44import {
55 MAX_RELAY_HOPS ,
66 normalizeInboundEventType ,
7+ normalizeWebhookEventSubscriptions ,
78 parseRelayHop ,
89 relayEventType ,
910} from "../lib/webhook-events.ts" ;
@@ -23,6 +24,42 @@ test("inbound webhook event types reject non-string and unsafe values", () => {
2324 assert . equal ( normalizeInboundEventType ( "x" . repeat ( 81 ) ) , null ) ;
2425} ) ;
2526
27+ test ( "outbound subscriptions trim and deduplicate event names" , ( ) => {
28+ assert . deepEqual (
29+ normalizeWebhookEventSubscriptions ( [
30+ " build.finished " ,
31+ "deploy.failed" ,
32+ "build.finished" ,
33+ "" ,
34+ ] ) ,
35+ [ "build.finished" , "deploy.failed" ] ,
36+ ) ;
37+ } ) ;
38+
39+ test ( "blank outbound subscriptions mean all events" , ( ) => {
40+ for ( const value of [ undefined , null , [ ] , [ "" ] , [ " " , "" ] ] ) {
41+ assert . deepEqual ( normalizeWebhookEventSubscriptions ( value ) , [ "*" ] ) ;
42+ }
43+ assert . deepEqual (
44+ normalizeWebhookEventSubscriptions ( [ "build.finished" , "*" , "deploy.failed" , "*" ] ) ,
45+ [ "*" ] ,
46+ ) ;
47+ } ) ;
48+
49+ test ( "outbound subscriptions reject malformed arrays and event names" , ( ) => {
50+ for ( const value of [
51+ "build.finished" ,
52+ { event : "build.finished" } ,
53+ [ "build finished" ] ,
54+ [ ".hidden" ] ,
55+ [ "x" . repeat ( 81 ) ] ,
56+ [ "build.finished" , 42 ] ,
57+ [ "*" , "not valid" ] ,
58+ ] ) {
59+ assert . equal ( normalizeWebhookEventSubscriptions ( value ) , null ) ;
60+ }
61+ } ) ;
62+
2663test ( "relayed event types are prefixed exactly once" , ( ) => {
2764 assert . equal ( relayEventType ( "payment.succeeded" ) , "inbound.payment.succeeded" ) ;
2865 assert . equal ( relayEventType ( null ) , "inbound.event" ) ;
0 commit comments