@@ -77,3 +77,57 @@ func TestWebhookCRUD(t *testing.T) {
7777 }
7878 assertResult (t , h .Run ("webhook" , "show" , "--board" , boardID , webhookID ), harness .ExitNotFound )
7979}
80+
81+ func TestWebhookDeliveries (t * testing.T ) {
82+ h := newHarness (t )
83+ boardID := createBoard (t , h )
84+ cardNum := createCard (t , h , boardID )
85+ name := "CLI Delivery Hook " + strconv .FormatInt (time .Now ().UnixNano (), 10 )
86+
87+ create := h .Run ("webhook" , "create" ,
88+ "--board" , boardID ,
89+ "--name" , name ,
90+ "--url" , "https://example.com/fizzy-cli-webhook-deliveries" ,
91+ "--actions" , "card_closed" ,
92+ )
93+ assertOK (t , create )
94+ webhookID := create .GetIDFromLocation ()
95+ if webhookID == "" {
96+ webhookID = create .GetDataString ("id" )
97+ }
98+ if webhookID == "" {
99+ t .Fatal ("no webhook ID in create response" )
100+ }
101+ t .Cleanup (func () {
102+ newHarness (t ).Run ("webhook" , "delete" , "--board" , boardID , webhookID )
103+ })
104+
105+ assertOK (t , h .Run ("card" , "close" , strconv .Itoa (cardNum )))
106+
107+ var deliveries * harness.Result
108+ for attempt := 0 ; attempt < 15 ; attempt ++ {
109+ r := h .Run ("webhook" , "deliveries" , "--board" , boardID , webhookID )
110+ if r .ExitCode == harness .ExitSuccess && len (r .GetDataArray ()) > 0 {
111+ deliveries = r
112+ break
113+ }
114+ time .Sleep (200 * time .Millisecond )
115+ }
116+ if deliveries == nil {
117+ t .Fatal ("expected at least one webhook delivery after triggering card_closed" )
118+ }
119+
120+ assertOK (t , deliveries )
121+ if len (deliveries .GetDataArray ()) == 0 {
122+ t .Fatal ("expected webhook deliveries to be non-empty" )
123+ }
124+ first := asMap (deliveries .GetDataArray ()[0 ])
125+ if mapValueString (first , "id" ) == "" {
126+ t .Fatal ("expected delivery id" )
127+ }
128+ if mapValueString (first , "state" ) == "" {
129+ t .Fatal ("expected delivery state" )
130+ }
131+
132+ assertOK (t , h .Run ("webhook" , "deliveries" , "--board" , boardID , webhookID , "--all" ))
133+ }
0 commit comments