|
5 | 5 | "strconv" |
6 | 6 | "strings" |
7 | 7 | "testing" |
| 8 | + "time" |
8 | 9 |
|
9 | 10 | "github.com/basecamp/fizzy-cli/e2e/harness" |
10 | 11 | ) |
@@ -241,3 +242,74 @@ func TestOutputContractShowCommands(t *testing.T) { |
241 | 242 | }) |
242 | 243 | } |
243 | 244 | } |
| 245 | + |
| 246 | +func TestOutputContractWebhookDeliveries(t *testing.T) { |
| 247 | + h := newHarness(t) |
| 248 | + boardID := createBoard(t, h) |
| 249 | + cardNum := createCard(t, h, boardID) |
| 250 | + create := h.Run("webhook", "create", "--board", boardID, "--name", "Output Contract Hook", "--url", "https://example.com/fizzy-cli-output-contract", "--actions", "card_closed") |
| 251 | + assertOK(t, create) |
| 252 | + webhookID := create.GetIDFromLocation() |
| 253 | + if webhookID == "" { |
| 254 | + webhookID = create.GetDataString("id") |
| 255 | + } |
| 256 | + if webhookID == "" { |
| 257 | + t.Fatal("expected webhook ID in create response") |
| 258 | + } |
| 259 | + t.Cleanup(func() { newHarness(t).Run("webhook", "delete", "--board", boardID, webhookID) }) |
| 260 | + |
| 261 | + assertOK(t, h.Run("card", "close", strconv.Itoa(cardNum))) |
| 262 | + |
| 263 | + var ready bool |
| 264 | + for attempt := 0; attempt < 15; attempt++ { |
| 265 | + result := h.Run("webhook", "deliveries", "--board", boardID, webhookID) |
| 266 | + if result.ExitCode == harness.ExitSuccess && len(result.GetDataArray()) > 0 { |
| 267 | + ready = true |
| 268 | + break |
| 269 | + } |
| 270 | + time.Sleep(200 * time.Millisecond) |
| 271 | + } |
| 272 | + if !ready { |
| 273 | + t.Fatal("expected webhook deliveries to contain at least one item") |
| 274 | + } |
| 275 | + |
| 276 | + baseArgs := []string{"webhook", "deliveries", "--board", boardID, webhookID} |
| 277 | + for _, f := range listFlagSuite() { |
| 278 | + f := f |
| 279 | + t.Run(f.name, func(t *testing.T) { |
| 280 | + args := append(append([]string(nil), baseArgs...), f.extra...) |
| 281 | + result := h.Run(args...) |
| 282 | + if result.ExitCode != harness.ExitSuccess { |
| 283 | + t.Fatalf("expected exit code 0, got %d\nstdout: %s\nstderr: %s", result.ExitCode, result.Stdout, result.Stderr) |
| 284 | + } |
| 285 | + f.check(t, result) |
| 286 | + }) |
| 287 | + } |
| 288 | +} |
| 289 | + |
| 290 | +func TestOutputContractUserExportShow(t *testing.T) { |
| 291 | + h := newHarness(t) |
| 292 | + userID := currentUserID(t, h) |
| 293 | + create := h.Run("user", "export-create", userID) |
| 294 | + assertOK(t, create) |
| 295 | + exportID := create.GetDataString("id") |
| 296 | + if exportID == "" { |
| 297 | + exportID = mapValueString(create.GetDataMap(), "id") |
| 298 | + } |
| 299 | + if exportID == "" { |
| 300 | + t.Fatal("expected user export ID in create response") |
| 301 | + } |
| 302 | + |
| 303 | + baseArgs := []string{"user", "export-show", userID, exportID} |
| 304 | + for _, f := range showFlagSuite() { |
| 305 | + f := f |
| 306 | + t.Run(f.name, func(t *testing.T) { |
| 307 | + args := append(append([]string(nil), baseArgs...), f.extra...) |
| 308 | + result := h.Run(args...) |
| 309 | + if result.ExitCode != harness.ExitSuccess { |
| 310 | + t.Fatalf("expected exit code 0, got %d\nstdout: %s\nstderr: %s", result.ExitCode, result.Stdout, result.Stderr) |
| 311 | + } |
| 312 | + f.check(t, result) |
| 313 | + }) |
| 314 | + } |
| 315 | +} |
0 commit comments