Skip to content

Commit a0d56d1

Browse files
committed
Add webhooks CLI commands
1 parent 64c3792 commit a0d56d1

File tree

6 files changed

+761
-0
lines changed

6 files changed

+761
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package cmdtest
2+
3+
import (
4+
"context"
5+
"errors"
6+
"flag"
7+
"io"
8+
"strings"
9+
"testing"
10+
)
11+
12+
func TestWebhooksValidationErrors(t *testing.T) {
13+
tests := []struct {
14+
name string
15+
args []string
16+
wantErr string
17+
}{
18+
{
19+
name: "list missing app",
20+
args: []string{"webhooks", "list"},
21+
wantErr: "--app is required",
22+
},
23+
{
24+
name: "get missing webhook id",
25+
args: []string{"webhooks", "get"},
26+
wantErr: "--webhook-id is required",
27+
},
28+
{
29+
name: "create missing app",
30+
args: []string{"webhooks", "create", "--name", "Build Updates", "--url", "https://example.com/webhook", "--secret", "secret", "--events", "BUILD_UPLOAD_STATE_UPDATED", "--enabled", "true"},
31+
wantErr: "--app is required",
32+
},
33+
{
34+
name: "create missing name",
35+
args: []string{"webhooks", "create", "--app", "APP_ID", "--url", "https://example.com/webhook", "--secret", "secret", "--events", "BUILD_UPLOAD_STATE_UPDATED", "--enabled", "true"},
36+
wantErr: "--name is required",
37+
},
38+
{
39+
name: "create missing url",
40+
args: []string{"webhooks", "create", "--app", "APP_ID", "--name", "Build Updates", "--secret", "secret", "--events", "BUILD_UPLOAD_STATE_UPDATED", "--enabled", "true"},
41+
wantErr: "--url is required",
42+
},
43+
{
44+
name: "create missing secret",
45+
args: []string{"webhooks", "create", "--app", "APP_ID", "--name", "Build Updates", "--url", "https://example.com/webhook", "--events", "BUILD_UPLOAD_STATE_UPDATED", "--enabled", "true"},
46+
wantErr: "--secret is required",
47+
},
48+
{
49+
name: "create missing events",
50+
args: []string{"webhooks", "create", "--app", "APP_ID", "--name", "Build Updates", "--url", "https://example.com/webhook", "--secret", "secret", "--enabled", "true"},
51+
wantErr: "--events is required",
52+
},
53+
{
54+
name: "create missing enabled",
55+
args: []string{"webhooks", "create", "--app", "APP_ID", "--name", "Build Updates", "--url", "https://example.com/webhook", "--secret", "secret", "--events", "BUILD_UPLOAD_STATE_UPDATED"},
56+
wantErr: "--enabled is required",
57+
},
58+
{
59+
name: "update missing webhook id",
60+
args: []string{"webhooks", "update", "--url", "https://example.com/webhook"},
61+
wantErr: "--webhook-id is required",
62+
},
63+
{
64+
name: "update missing fields",
65+
args: []string{"webhooks", "update", "--webhook-id", "wh-1"},
66+
wantErr: "--name, --url, --secret, --events, or --enabled is required",
67+
},
68+
{
69+
name: "delete missing confirm",
70+
args: []string{"webhooks", "delete", "--webhook-id", "wh-1"},
71+
wantErr: "--confirm is required",
72+
},
73+
{
74+
name: "delete missing webhook id",
75+
args: []string{"webhooks", "delete", "--confirm"},
76+
wantErr: "--webhook-id is required",
77+
},
78+
{
79+
name: "deliveries missing webhook id",
80+
args: []string{"webhooks", "deliveries"},
81+
wantErr: "--webhook-id is required",
82+
},
83+
{
84+
name: "deliveries redeliver missing delivery id",
85+
args: []string{"webhooks", "deliveries", "redeliver"},
86+
wantErr: "--delivery-id is required",
87+
},
88+
{
89+
name: "ping missing webhook id",
90+
args: []string{"webhooks", "ping"},
91+
wantErr: "--webhook-id is required",
92+
},
93+
}
94+
95+
for _, test := range tests {
96+
t.Run(test.name, func(t *testing.T) {
97+
root := RootCommand("1.2.3")
98+
root.FlagSet.SetOutput(io.Discard)
99+
100+
stdout, stderr := captureOutput(t, func() {
101+
if err := root.Parse(test.args); err != nil {
102+
t.Fatalf("parse error: %v", err)
103+
}
104+
err := root.Run(context.Background())
105+
if !errors.Is(err, flag.ErrHelp) {
106+
t.Fatalf("expected ErrHelp, got %v", err)
107+
}
108+
})
109+
110+
if stdout != "" {
111+
t.Fatalf("expected empty stdout, got %q", stdout)
112+
}
113+
if !strings.Contains(stderr, test.wantErr) {
114+
t.Fatalf("expected error %q, got %q", test.wantErr, stderr)
115+
}
116+
})
117+
}
118+
}

internal/cli/registry/registry.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import (
5454
"github.com/rudrankriyam/App-Store-Connect-CLI/internal/cli/users"
5555
"github.com/rudrankriyam/App-Store-Connect-CLI/internal/cli/versions"
5656
"github.com/rudrankriyam/App-Store-Connect-CLI/internal/cli/winbackoffers"
57+
"github.com/rudrankriyam/App-Store-Connect-CLI/internal/cli/webhooks"
5758
"github.com/rudrankriyam/App-Store-Connect-CLI/internal/cli/xcodecloud"
5859
)
5960

@@ -88,6 +89,7 @@ func Subcommands(version string) []*ffcli.Command {
8889
apps.AppSetupCommand(),
8990
apps.AppTagsCommand(),
9091
marketplace.MarketplaceCommand(),
92+
webhooks.WebhooksCommand(),
9193
nominations.NominationsCommand(),
9294
bundleids.BundleIDsCommand(),
9395
merchantids.MerchantIDsCommand(),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package webhooks
2+
3+
import (
4+
"context"
5+
6+
"github.com/peterbourgon/ff/v3/ffcli"
7+
8+
"github.com/rudrankriyam/App-Store-Connect-CLI/internal/asc"
9+
"github.com/rudrankriyam/App-Store-Connect-CLI/internal/cli/shared"
10+
)
11+
12+
func DefaultUsageFunc(c *ffcli.Command) string {
13+
return shared.DefaultUsageFunc(c)
14+
}
15+
16+
func getASCClient() (*asc.Client, error) {
17+
return shared.GetASCClient()
18+
}
19+
20+
func contextWithTimeout(ctx context.Context) (context.Context, context.CancelFunc) {
21+
return shared.ContextWithTimeout(ctx)
22+
}
23+
24+
func printOutput(data interface{}, format string, pretty bool) error {
25+
return shared.PrintOutput(data, format, pretty)
26+
}
27+
28+
func validateNextURL(next string) error {
29+
return shared.ValidateNextURL(next)
30+
}
31+
32+
func resolveAppID(appID string) string {
33+
return shared.ResolveAppID(appID)
34+
}
35+
36+
func splitCSV(value string) []string {
37+
return shared.SplitCSV(value)
38+
}

0 commit comments

Comments
 (0)