diff --git a/github/apps_marketplace.go b/github/apps_marketplace.go index 13d09f2efba..f58c6ff3932 100644 --- a/github/apps_marketplace.go +++ b/github/apps_marketplace.go @@ -75,6 +75,20 @@ type MarketplacePlanAccount struct { MarketplacePendingChange *MarketplacePendingChange `json:"marketplace_pending_change,omitempty"` } +// SetStubbed configures the MarketplaceService Stubbed property. +// +// GitHub API docs: https://docs.github.com/en/developers/github-marketplace/testing-your-app#testing-apis +func (s *MarketplaceService) SetStubbed(stubbed bool) { + s.Stubbed = stubbed +} + +// GetStubbed returns the MarketplaceService Stubbed property. +// +// GitHub API docs: https://docs.github.com/en/developers/github-marketplace/testing-your-app#testing-apis +func (s *MarketplaceService) GetStubbed() bool { + return s.Stubbed +} + // ListPlans lists all plans for your Marketplace listing. // // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps#list-plans @@ -149,7 +163,7 @@ func (s *MarketplaceService) GetPlanAccountForAccount(ctx context.Context, accou // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#list-subscriptions-for-the-authenticated-user func (s *MarketplaceService) ListMarketplacePurchasesForUser(ctx context.Context, opts *ListOptions) ([]*MarketplacePurchase, *Response, error) { uri := "user/marketplace_purchases" - if s.Stubbed { + if s.GetStubbed() { uri = "user/marketplace_purchases/stubbed" } @@ -173,7 +187,7 @@ func (s *MarketplaceService) ListMarketplacePurchasesForUser(ctx context.Context func (s *MarketplaceService) marketplaceURI(endpoint string) string { url := "marketplace_listing" - if s.Stubbed { + if s.GetStubbed() { url = "marketplace_listing/stubbed" } return url + "/" + endpoint diff --git a/github/apps_marketplace_test.go b/github/apps_marketplace_test.go index fd2d26cf1fc..f596ff0feec 100644 --- a/github/apps_marketplace_test.go +++ b/github/apps_marketplace_test.go @@ -27,7 +27,7 @@ func TestMarketplaceService_ListPlans(t *testing.T) { }) opt := &ListOptions{Page: 1, PerPage: 2} - client.Marketplace.Stubbed = false + client.Marketplace.SetStubbed(false) ctx := context.Background() plans, _, err := client.Marketplace.ListPlans(ctx, opt) if err != nil { @@ -59,7 +59,7 @@ func TestMarketplaceService_Stubbed_ListPlans(t *testing.T) { }) opt := &ListOptions{Page: 1, PerPage: 2} - client.Marketplace.Stubbed = true + client.Marketplace.SetStubbed(true) ctx := context.Background() plans, _, err := client.Marketplace.ListPlans(ctx, opt) if err != nil { @@ -82,7 +82,7 @@ func TestMarketplaceService_ListPlanAccountsForPlan(t *testing.T) { }) opt := &ListOptions{Page: 1, PerPage: 2} - client.Marketplace.Stubbed = false + client.Marketplace.SetStubbed(false) ctx := context.Background() accounts, _, err := client.Marketplace.ListPlanAccountsForPlan(ctx, 1, opt) if err != nil { @@ -114,7 +114,7 @@ func TestMarketplaceService_Stubbed_ListPlanAccountsForPlan(t *testing.T) { }) opt := &ListOptions{Page: 1, PerPage: 2} - client.Marketplace.Stubbed = true + client.Marketplace.SetStubbed(true) ctx := context.Background() accounts, _, err := client.Marketplace.ListPlanAccountsForPlan(ctx, 1, opt) if err != nil { @@ -136,7 +136,7 @@ func TestMarketplaceService_GetPlanAccountForAccount(t *testing.T) { fmt.Fprint(w, `{"id":1, "marketplace_pending_change": {"id": 77}}`) }) - client.Marketplace.Stubbed = false + client.Marketplace.SetStubbed(false) ctx := context.Background() account, _, err := client.Marketplace.GetPlanAccountForAccount(ctx, 1) if err != nil { @@ -167,7 +167,7 @@ func TestMarketplaceService_Stubbed_GetPlanAccountForAccount(t *testing.T) { fmt.Fprint(w, `{"id":1}`) }) - client.Marketplace.Stubbed = true + client.Marketplace.SetStubbed(true) ctx := context.Background() account, _, err := client.Marketplace.GetPlanAccountForAccount(ctx, 1) if err != nil { @@ -190,7 +190,7 @@ func TestMarketplaceService_ListMarketplacePurchasesForUser(t *testing.T) { }) opt := &ListOptions{Page: 1, PerPage: 2} - client.Marketplace.Stubbed = false + client.Marketplace.SetStubbed(false) ctx := context.Background() purchases, _, err := client.Marketplace.ListMarketplacePurchasesForUser(ctx, opt) if err != nil { @@ -222,7 +222,7 @@ func TestMarketplaceService_Stubbed_ListMarketplacePurchasesForUser(t *testing.T }) opt := &ListOptions{Page: 1, PerPage: 2} - client.Marketplace.Stubbed = true + client.Marketplace.SetStubbed(true) ctx := context.Background() purchases, _, err := client.Marketplace.ListMarketplacePurchasesForUser(ctx, opt) if err != nil { diff --git a/github/github-interfaces.go b/github/github-interfaces.go index 87f4bdaa04a..c4bf7d5295c 100644 --- a/github/github-interfaces.go +++ b/github/github-interfaces.go @@ -591,11 +591,15 @@ var _ LicensesServiceInterface = &LicensesService{} type MarketplaceServiceInterface interface { GetPlanAccountForAccount(ctx context.Context, accountID int64) (*MarketplacePlanAccount, *Response, error) + GetStubbed() bool + ListMarketplacePurchasesForUser(ctx context.Context, opts *ListOptions) ([]*MarketplacePurchase, *Response, error) ListPlanAccountsForPlan(ctx context.Context, planID int64, opts *ListOptions) ([]*MarketplacePlanAccount, *Response, error) ListPlans(ctx context.Context, opts *ListOptions) ([]*MarketplacePlan, *Response, error) + + SetStubbed(stubbed bool) } // MarketplaceService implements the MarketplaceServiceInterface. diff --git a/github/github.go b/github/github.go index 00121639a47..6ecf5d20a76 100644 --- a/github/github.go +++ b/github/github.go @@ -171,7 +171,7 @@ type Client struct { IssueImport IssueImportServiceInterface Issues IssuesServiceInterface Licenses LicensesServiceInterface - Marketplace *MarketplaceService + Marketplace MarketplaceServiceInterface Migrations MigrationServiceInterface Organizations OrganizationsServiceInterface Projects ProjectsServiceInterface