+
Skip to content

Fix invalid response and rename ListPlanAccountsForAccount (fixes #1270) #1827

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
merged 7 commits into from
Apr 1, 2021
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
37 changes: 15 additions & 22 deletions github/apps_marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ type MarketplacePlan struct {
// MarketplacePurchase represents a GitHub Apps Marketplace Purchase.
type MarketplacePurchase struct {
// BillingCycle can be one of the values "yearly", "monthly" or nil.
BillingCycle *string `json:"billing_cycle,omitempty"`
NextBillingDate *Timestamp `json:"next_billing_date,omitempty"`
UnitCount *int `json:"unit_count,omitempty"`
Plan *MarketplacePlan `json:"plan,omitempty"`
Account *MarketplacePlanAccount `json:"account,omitempty"`
OnFreeTrial *bool `json:"on_free_trial,omitempty"`
FreeTrialEndsOn *Timestamp `json:"free_trial_ends_on,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
BillingCycle *string `json:"billing_cycle,omitempty"`
NextBillingDate *Timestamp `json:"next_billing_date,omitempty"`
UnitCount *int `json:"unit_count,omitempty"`
Plan *MarketplacePlan `json:"plan,omitempty"`
OnFreeTrial *bool `json:"on_free_trial,omitempty"`
FreeTrialEndsOn *Timestamp `json:"free_trial_ends_on,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
}

// MarketplacePendingChange represents a pending change to a GitHub Apps Marketplace Plan.
Expand All @@ -70,9 +69,7 @@ type MarketplacePlanAccount struct {
URL *string `json:"url,omitempty"`
Type *string `json:"type,omitempty"`
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Login *string `json:"login,omitempty"`
Email *string `json:"email,omitempty"`
OrganizationBillingEmail *string `json:"organization_billing_email,omitempty"`
MarketplacePurchase *MarketplacePurchase `json:"marketplace_purchase,omitempty"`
MarketplacePendingChange *MarketplacePendingChange `json:"marketplace_pending_change,omitempty"`
Expand Down Expand Up @@ -104,7 +101,7 @@ func (s *MarketplaceService) ListPlans(ctx context.Context, opts *ListOptions) (

// ListPlanAccountsForPlan lists all GitHub accounts (user or organization) on a specific plan.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#list-all-github-accounts-user-or-organization-on-a-specific-plan
// GitHub API docs: https://docs.github.com/en/rest/reference/apps#list-accounts-for-a-plan
func (s *MarketplaceService) ListPlanAccountsForPlan(ctx context.Context, planID int64, opts *ListOptions) ([]*MarketplacePlanAccount, *Response, error) {
uri := s.marketplaceURI(fmt.Sprintf("plans/%v/accounts", planID))
u, err := addOptions(uri, opts)
Expand All @@ -126,28 +123,24 @@ func (s *MarketplaceService) ListPlanAccountsForPlan(ctx context.Context, planID
return accounts, resp, nil
}

// ListPlanAccountsForAccount lists all GitHub accounts (user or organization) associated with an account.
// GetPlanAccountForAccount get GitHub account (user or organization) associated with an account.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/apps/#check-if-a-github-account-is-associated-with-any-marketplace-listing
func (s *MarketplaceService) ListPlanAccountsForAccount(ctx context.Context, accountID int64, opts *ListOptions) ([]*MarketplacePlanAccount, *Response, error) {
// GitHub API docs: https://docs.github.com/en/rest/reference/apps#get-a-subscription-plan-for-an-account
func (s *MarketplaceService) GetPlanAccountForAccount(ctx context.Context, accountID int64) (*MarketplacePlanAccount, *Response, error) {
uri := s.marketplaceURI(fmt.Sprintf("accounts/%v", accountID))
u, err := addOptions(uri, opts)
if err != nil {
return nil, nil, err
}

req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", uri, nil)
if err != nil {
return nil, nil, err
}

var accounts []*MarketplacePlanAccount
resp, err := s.client.Do(ctx, req, &accounts)
var account *MarketplacePlanAccount
resp, err := s.client.Do(ctx, req, &account)
if err != nil {
return nil, resp, err
}

return accounts, resp, nil
return account, resp, nil
}

// ListMarketplacePurchasesForUser lists all GitHub marketplace purchases made by a user.
Expand Down
34 changes: 16 additions & 18 deletions github/apps_marketplace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,58 +127,56 @@ func TestMarketplaceService_Stubbed_ListPlanAccountsForPlan(t *testing.T) {
}
}

func TestMarketplaceService_ListPlanAccountsForAccount(t *testing.T) {
func TestMarketplaceService_GetPlanAccountForAccount(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/marketplace_listing/accounts/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"id":1, "marketplace_pending_change": {"id": 77}}]`)
fmt.Fprint(w, `{"id":1, "marketplace_pending_change": {"id": 77}}`)
})

opt := &ListOptions{Page: 1, PerPage: 2}
client.Marketplace.Stubbed = false
ctx := context.Background()
accounts, _, err := client.Marketplace.ListPlanAccountsForAccount(ctx, 1, opt)
account, _, err := client.Marketplace.GetPlanAccountForAccount(ctx, 1)
if err != nil {
t.Errorf("Marketplace.ListPlanAccountsForAccount returned error: %v", err)
t.Errorf("Marketplace.GetPlanAccountForAccount returned error: %v", err)
}

want := []*MarketplacePlanAccount{{ID: Int64(1), MarketplacePendingChange: &MarketplacePendingChange{ID: Int64(77)}}}
if !reflect.DeepEqual(accounts, want) {
t.Errorf("Marketplace.ListPlanAccountsForAccount returned %+v, want %+v", accounts, want)
want := &MarketplacePlanAccount{ID: Int64(1), MarketplacePendingChange: &MarketplacePendingChange{ID: Int64(77)}}
if !reflect.DeepEqual(account, want) {
t.Errorf("Marketplace.GetPlanAccountForAccount returned %+v, want %+v", account, want)
}

const methodName = "ListPlanAccountsForAccount"
const methodName = "GetPlanAccountForAccount"
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Marketplace.ListPlanAccountsForAccount(ctx, 1, opt)
got, resp, err := client.Marketplace.GetPlanAccountForAccount(ctx, 1)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

func TestMarketplaceService_Stubbed_ListPlanAccountsForAccount(t *testing.T) {
func TestMarketplaceService_Stubbed_GetPlanAccountForAccount(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/marketplace_listing/stubbed/accounts/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"id":1}]`)
fmt.Fprint(w, `{"id":1}`)
})

opt := &ListOptions{Page: 1, PerPage: 2}
client.Marketplace.Stubbed = true
ctx := context.Background()
accounts, _, err := client.Marketplace.ListPlanAccountsForAccount(ctx, 1, opt)
account, _, err := client.Marketplace.GetPlanAccountForAccount(ctx, 1)
if err != nil {
t.Errorf("Marketplace.ListPlanAccountsForAccount (Stubbed) returned error: %v", err)
t.Errorf("Marketplace.GetPlanAccountForAccount (Stubbed) returned error: %v", err)
}

want := []*MarketplacePlanAccount{{ID: Int64(1)}}
if !reflect.DeepEqual(accounts, want) {
t.Errorf("Marketplace.ListPlanAccountsForAccount (Stubbed) returned %+v, want %+v", accounts, want)
want := &MarketplacePlanAccount{ID: Int64(1)}
if !reflect.DeepEqual(account, want) {
t.Errorf("Marketplace.GetPlanAccountForAccount (Stubbed) returned %+v, want %+v", account, want)
}
}

Expand Down
24 changes: 0 additions & 24 deletions github/github-accessors.go

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

27 changes: 0 additions & 27 deletions github/github-accessors_test.go

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

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载