Skip to content

Create getter and setter for MarketplaceService.Stubbed #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions github/apps_marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two new methods need standard godoc-style comment strings.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how I managed to miss this 😔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, added the doc strings

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
Expand Down Expand Up @@ -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"
}

Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions github/apps_marketplace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions github/github-interfaces.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ type Client struct {
IssueImport IssueImportServiceInterface
Issues IssuesServiceInterface
Licenses LicensesServiceInterface
Marketplace *MarketplaceService
Marketplace MarketplaceServiceInterface
Migrations MigrationServiceInterface
Organizations OrganizationsServiceInterface
Projects ProjectsServiceInterface
Expand Down