github.com/google/go-github/v33@v33.0.0/github/apps_marketplace_test.go (about)

     1  // Copyright 2017 The go-github AUTHORS. All rights reserved.
     2  //
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package github
     7  
     8  import (
     9  	"context"
    10  	"fmt"
    11  	"net/http"
    12  	"reflect"
    13  	"testing"
    14  )
    15  
    16  func TestMarketplaceService_ListPlans(t *testing.T) {
    17  	client, mux, _, teardown := setup()
    18  	defer teardown()
    19  
    20  	mux.HandleFunc("/marketplace_listing/plans", func(w http.ResponseWriter, r *http.Request) {
    21  		testMethod(t, r, "GET")
    22  		testFormValues(t, r, values{
    23  			"page":     "1",
    24  			"per_page": "2",
    25  		})
    26  		fmt.Fprint(w, `[{"id":1}]`)
    27  	})
    28  
    29  	opt := &ListOptions{Page: 1, PerPage: 2}
    30  	client.Marketplace.Stubbed = false
    31  	plans, _, err := client.Marketplace.ListPlans(context.Background(), opt)
    32  	if err != nil {
    33  		t.Errorf("Marketplace.ListPlans returned error: %v", err)
    34  	}
    35  
    36  	want := []*MarketplacePlan{{ID: Int64(1)}}
    37  	if !reflect.DeepEqual(plans, want) {
    38  		t.Errorf("Marketplace.ListPlans returned %+v, want %+v", plans, want)
    39  	}
    40  }
    41  
    42  func TestMarketplaceService_Stubbed_ListPlans(t *testing.T) {
    43  	client, mux, _, teardown := setup()
    44  	defer teardown()
    45  
    46  	mux.HandleFunc("/marketplace_listing/stubbed/plans", func(w http.ResponseWriter, r *http.Request) {
    47  		testMethod(t, r, "GET")
    48  		fmt.Fprint(w, `[{"id":1}]`)
    49  	})
    50  
    51  	opt := &ListOptions{Page: 1, PerPage: 2}
    52  	client.Marketplace.Stubbed = true
    53  	plans, _, err := client.Marketplace.ListPlans(context.Background(), opt)
    54  	if err != nil {
    55  		t.Errorf("Marketplace.ListPlans (Stubbed) returned error: %v", err)
    56  	}
    57  
    58  	want := []*MarketplacePlan{{ID: Int64(1)}}
    59  	if !reflect.DeepEqual(plans, want) {
    60  		t.Errorf("Marketplace.ListPlans (Stubbed) returned %+v, want %+v", plans, want)
    61  	}
    62  }
    63  
    64  func TestMarketplaceService_ListPlanAccountsForPlan(t *testing.T) {
    65  	client, mux, _, teardown := setup()
    66  	defer teardown()
    67  
    68  	mux.HandleFunc("/marketplace_listing/plans/1/accounts", func(w http.ResponseWriter, r *http.Request) {
    69  		testMethod(t, r, "GET")
    70  		fmt.Fprint(w, `[{"id":1}]`)
    71  	})
    72  
    73  	opt := &ListOptions{Page: 1, PerPage: 2}
    74  	client.Marketplace.Stubbed = false
    75  	accounts, _, err := client.Marketplace.ListPlanAccountsForPlan(context.Background(), 1, opt)
    76  	if err != nil {
    77  		t.Errorf("Marketplace.ListPlanAccountsForPlan returned error: %v", err)
    78  	}
    79  
    80  	want := []*MarketplacePlanAccount{{ID: Int64(1)}}
    81  	if !reflect.DeepEqual(accounts, want) {
    82  		t.Errorf("Marketplace.ListPlanAccountsForPlan returned %+v, want %+v", accounts, want)
    83  	}
    84  }
    85  
    86  func TestMarketplaceService_Stubbed_ListPlanAccountsForPlan(t *testing.T) {
    87  	client, mux, _, teardown := setup()
    88  	defer teardown()
    89  
    90  	mux.HandleFunc("/marketplace_listing/stubbed/plans/1/accounts", func(w http.ResponseWriter, r *http.Request) {
    91  		testMethod(t, r, "GET")
    92  		fmt.Fprint(w, `[{"id":1}]`)
    93  	})
    94  
    95  	opt := &ListOptions{Page: 1, PerPage: 2}
    96  	client.Marketplace.Stubbed = true
    97  	accounts, _, err := client.Marketplace.ListPlanAccountsForPlan(context.Background(), 1, opt)
    98  	if err != nil {
    99  		t.Errorf("Marketplace.ListPlanAccountsForPlan (Stubbed) returned error: %v", err)
   100  	}
   101  
   102  	want := []*MarketplacePlanAccount{{ID: Int64(1)}}
   103  	if !reflect.DeepEqual(accounts, want) {
   104  		t.Errorf("Marketplace.ListPlanAccountsForPlan (Stubbed) returned %+v, want %+v", accounts, want)
   105  	}
   106  }
   107  
   108  func TestMarketplaceService_ListPlanAccountsForAccount(t *testing.T) {
   109  	client, mux, _, teardown := setup()
   110  	defer teardown()
   111  
   112  	mux.HandleFunc("/marketplace_listing/accounts/1", func(w http.ResponseWriter, r *http.Request) {
   113  		testMethod(t, r, "GET")
   114  		fmt.Fprint(w, `[{"id":1, "marketplace_pending_change": {"id": 77}}]`)
   115  	})
   116  
   117  	opt := &ListOptions{Page: 1, PerPage: 2}
   118  	client.Marketplace.Stubbed = false
   119  	accounts, _, err := client.Marketplace.ListPlanAccountsForAccount(context.Background(), 1, opt)
   120  	if err != nil {
   121  		t.Errorf("Marketplace.ListPlanAccountsForAccount returned error: %v", err)
   122  	}
   123  
   124  	want := []*MarketplacePlanAccount{{ID: Int64(1), MarketplacePendingChange: &MarketplacePendingChange{ID: Int64(77)}}}
   125  	if !reflect.DeepEqual(accounts, want) {
   126  		t.Errorf("Marketplace.ListPlanAccountsForAccount returned %+v, want %+v", accounts, want)
   127  	}
   128  }
   129  
   130  func TestMarketplaceService_Stubbed_ListPlanAccountsForAccount(t *testing.T) {
   131  	client, mux, _, teardown := setup()
   132  	defer teardown()
   133  
   134  	mux.HandleFunc("/marketplace_listing/stubbed/accounts/1", func(w http.ResponseWriter, r *http.Request) {
   135  		testMethod(t, r, "GET")
   136  		fmt.Fprint(w, `[{"id":1}]`)
   137  	})
   138  
   139  	opt := &ListOptions{Page: 1, PerPage: 2}
   140  	client.Marketplace.Stubbed = true
   141  	accounts, _, err := client.Marketplace.ListPlanAccountsForAccount(context.Background(), 1, opt)
   142  	if err != nil {
   143  		t.Errorf("Marketplace.ListPlanAccountsForAccount (Stubbed) returned error: %v", err)
   144  	}
   145  
   146  	want := []*MarketplacePlanAccount{{ID: Int64(1)}}
   147  	if !reflect.DeepEqual(accounts, want) {
   148  		t.Errorf("Marketplace.ListPlanAccountsForAccount (Stubbed) returned %+v, want %+v", accounts, want)
   149  	}
   150  }
   151  
   152  func TestMarketplaceService_ListMarketplacePurchasesForUser(t *testing.T) {
   153  	client, mux, _, teardown := setup()
   154  	defer teardown()
   155  
   156  	mux.HandleFunc("/user/marketplace_purchases", func(w http.ResponseWriter, r *http.Request) {
   157  		testMethod(t, r, "GET")
   158  		fmt.Fprint(w, `[{"billing_cycle":"monthly"}]`)
   159  	})
   160  
   161  	opt := &ListOptions{Page: 1, PerPage: 2}
   162  	client.Marketplace.Stubbed = false
   163  	purchases, _, err := client.Marketplace.ListMarketplacePurchasesForUser(context.Background(), opt)
   164  	if err != nil {
   165  		t.Errorf("Marketplace.ListMarketplacePurchasesForUser returned error: %v", err)
   166  	}
   167  
   168  	want := []*MarketplacePurchase{{BillingCycle: String("monthly")}}
   169  	if !reflect.DeepEqual(purchases, want) {
   170  		t.Errorf("Marketplace.ListMarketplacePurchasesForUser returned %+v, want %+v", purchases, want)
   171  	}
   172  }
   173  
   174  func TestMarketplaceService_Stubbed_ListMarketplacePurchasesForUser(t *testing.T) {
   175  	client, mux, _, teardown := setup()
   176  	defer teardown()
   177  
   178  	mux.HandleFunc("/user/marketplace_purchases/stubbed", func(w http.ResponseWriter, r *http.Request) {
   179  		testMethod(t, r, "GET")
   180  		fmt.Fprint(w, `[{"billing_cycle":"monthly"}]`)
   181  	})
   182  
   183  	opt := &ListOptions{Page: 1, PerPage: 2}
   184  	client.Marketplace.Stubbed = true
   185  	purchases, _, err := client.Marketplace.ListMarketplacePurchasesForUser(context.Background(), opt)
   186  	if err != nil {
   187  		t.Errorf("Marketplace.ListMarketplacePurchasesForUser returned error: %v", err)
   188  	}
   189  
   190  	want := []*MarketplacePurchase{{BillingCycle: String("monthly")}}
   191  	if !reflect.DeepEqual(purchases, want) {
   192  		t.Errorf("Marketplace.ListMarketplacePurchasesForUser returned %+v, want %+v", purchases, want)
   193  	}
   194  }