Skip to content

Commit b861375

Browse files
Add fields support for marketplace search details
Co-authored-by: rudrankriyam <[email protected]>
1 parent d471dac commit b861375

File tree

5 files changed

+74
-3
lines changed

5 files changed

+74
-3
lines changed

internal/asc/client_http_marketplace_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,34 @@ func TestGetMarketplaceSearchDetailForApp_SendsRequest(t *testing.T) {
1717
if req.URL.Path != "/v1/apps/app-1/marketplaceSearchDetail" {
1818
t.Fatalf("expected path /v1/apps/app-1/marketplaceSearchDetail, got %s", req.URL.Path)
1919
}
20+
if req.URL.RawQuery != "" {
21+
t.Fatalf("expected no query params, got %s", req.URL.RawQuery)
22+
}
23+
assertAuthorized(t, req)
24+
}, response)
25+
26+
if _, err := client.GetMarketplaceSearchDetailForApp(context.Background(), "app-1", nil); err != nil {
27+
t.Fatalf("GetMarketplaceSearchDetailForApp() error: %v", err)
28+
}
29+
}
30+
31+
func TestGetMarketplaceSearchDetailForApp_WithFields(t *testing.T) {
32+
response := jsonResponse(http.StatusOK, `{"data":{"type":"marketplaceSearchDetails","id":"detail-1","attributes":{"catalogUrl":"https://example.com/catalog"}}}`)
33+
client := newTestClient(t, func(req *http.Request) {
34+
if req.Method != http.MethodGet {
35+
t.Fatalf("expected GET, got %s", req.Method)
36+
}
37+
if req.URL.Path != "/v1/apps/app-1/marketplaceSearchDetail" {
38+
t.Fatalf("expected path /v1/apps/app-1/marketplaceSearchDetail, got %s", req.URL.Path)
39+
}
40+
values := req.URL.Query()
41+
if values.Get("fields[marketplaceSearchDetails]") != "catalogUrl" {
42+
t.Fatalf("expected fields catalogUrl, got %q", values.Get("fields[marketplaceSearchDetails]"))
43+
}
2044
assertAuthorized(t, req)
2145
}, response)
2246

23-
if _, err := client.GetMarketplaceSearchDetailForApp(context.Background(), "app-1"); err != nil {
47+
if _, err := client.GetMarketplaceSearchDetailForApp(context.Background(), "app-1", []string{"catalogUrl"}); err != nil {
2448
t.Fatalf("GetMarketplaceSearchDetailForApp() error: %v", err)
2549
}
2650
}

internal/asc/client_queries.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,12 @@ func buildSubscriptionOfferCodeOneTimeUseCodesQuery(query *subscriptionOfferCode
830830
return values.Encode()
831831
}
832832

833+
func buildMarketplaceSearchDetailsFieldsQuery(fields []string) string {
834+
values := url.Values{}
835+
addCSV(values, "fields[marketplaceSearchDetails]", fields)
836+
return values.Encode()
837+
}
838+
833839
func buildMarketplaceWebhooksQuery(query *marketplaceWebhooksQuery) string {
834840
values := url.Values{}
835841
addCSV(values, "fields[marketplaceWebhooks]", query.fields)

internal/asc/marketplace.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,16 @@ type MarketplaceWebhookDeleteResult struct {
116116
}
117117

118118
// GetMarketplaceSearchDetailForApp retrieves marketplace search details for an app.
119-
func (c *Client) GetMarketplaceSearchDetailForApp(ctx context.Context, appID string) (*MarketplaceSearchDetailResponse, error) {
119+
func (c *Client) GetMarketplaceSearchDetailForApp(ctx context.Context, appID string, fields []string) (*MarketplaceSearchDetailResponse, error) {
120120
appID = strings.TrimSpace(appID)
121121
if appID == "" {
122122
return nil, fmt.Errorf("appID is required")
123123
}
124124

125125
path := fmt.Sprintf("/v1/apps/%s/marketplaceSearchDetail", appID)
126+
if queryString := buildMarketplaceSearchDetailsFieldsQuery(fields); queryString != "" {
127+
path += "?" + queryString
128+
}
126129
data, err := c.do(ctx, "GET", path, nil)
127130
if err != nil {
128131
return nil, err

internal/cli/marketplace/marketplace_search_details.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func MarketplaceSearchDetailsGetCommand() *ffcli.Command {
4646
fs := flag.NewFlagSet("get", flag.ExitOnError)
4747

4848
appID := fs.String("app", "", "App Store Connect app ID (or ASC_APP_ID env)")
49+
fields := fs.String("fields", "", "Fields to include: "+strings.Join(marketplaceSearchDetailFieldsList(), ", "))
4950
output := fs.String("output", "json", "Output format: json (default), table, markdown")
5051
pretty := fs.Bool("pretty", false, "Pretty-print JSON output")
5152

@@ -66,6 +67,11 @@ Examples:
6667
return flag.ErrHelp
6768
}
6869

70+
fieldsValue, err := normalizeMarketplaceSearchDetailFields(*fields)
71+
if err != nil {
72+
return fmt.Errorf("marketplace search-details get: %w", err)
73+
}
74+
6975
client, err := getASCClient()
7076
if err != nil {
7177
return fmt.Errorf("marketplace search-details get: %w", err)
@@ -74,7 +80,7 @@ Examples:
7480
requestCtx, cancel := contextWithTimeout(ctx)
7581
defer cancel()
7682

77-
detail, err := client.GetMarketplaceSearchDetailForApp(requestCtx, resolvedAppID)
83+
detail, err := client.GetMarketplaceSearchDetailForApp(requestCtx, resolvedAppID, fieldsValue)
7884
if err != nil {
7985
return fmt.Errorf("marketplace search-details get: failed to fetch: %w", err)
8086
}
@@ -245,3 +251,24 @@ Examples:
245251
},
246252
}
247253
}
254+
255+
func normalizeMarketplaceSearchDetailFields(value string) ([]string, error) {
256+
fields := splitCSV(value)
257+
if len(fields) == 0 {
258+
return nil, nil
259+
}
260+
allowed := map[string]struct{}{}
261+
for _, field := range marketplaceSearchDetailFieldsList() {
262+
allowed[field] = struct{}{}
263+
}
264+
for _, field := range fields {
265+
if _, ok := allowed[field]; !ok {
266+
return nil, fmt.Errorf("--fields must be one of: %s", strings.Join(marketplaceSearchDetailFieldsList(), ", "))
267+
}
268+
}
269+
return fields, nil
270+
}
271+
272+
func marketplaceSearchDetailFieldsList() []string {
273+
return []string{"catalogUrl"}
274+
}

internal/cli/marketplace/marketplace_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ func TestMarketplaceSearchDetailsGetCommand_MissingApp(t *testing.T) {
1919
}
2020
}
2121

22+
func TestMarketplaceSearchDetailsGetCommand_InvalidFields(t *testing.T) {
23+
cmd := MarketplaceSearchDetailsGetCommand()
24+
if err := cmd.FlagSet.Parse([]string{"--app", "APP_ID", "--fields", "invalid"}); err != nil {
25+
t.Fatalf("failed to parse flags: %v", err)
26+
}
27+
28+
if err := cmd.Exec(context.Background(), []string{}); err == nil || err == flag.ErrHelp {
29+
t.Fatalf("expected validation error for invalid --fields, got %v", err)
30+
}
31+
}
32+
2233
func TestMarketplaceSearchDetailsCreateCommand_MissingApp(t *testing.T) {
2334
t.Setenv("ASC_APP_ID", "")
2435

0 commit comments

Comments
 (0)