Total Lines | 57 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package mollie |
||
2 | |||
3 | import ( |
||
4 | "context" |
||
5 | "fmt" |
||
6 | "net/http" |
||
7 | "reflect" |
||
8 | "testing" |
||
9 | |||
10 | "github.com/VictorAvelar/mollie-api-go/mollie/testdata" |
||
11 | ) |
||
12 | |||
13 | func TestPaymentsList(t *testing.T) { |
||
14 | setup() |
||
15 | defer teardown() |
||
16 | paymentsAPIEndpoint := "/v2/payments" |
||
17 | |||
18 | testMux.HandleFunc(paymentsAPIEndpoint, func(w http.ResponseWriter, r *http.Request) { |
||
19 | _, ok := r.Header[AuthHeader] |
||
20 | if !ok { |
||
21 | w.WriteHeader(http.StatusUnauthorized) |
||
22 | } |
||
23 | raw := testdata.ListPaymentsExample |
||
24 | fmt.Fprint(w, raw) |
||
25 | }) |
||
26 | |||
27 | err := testClient.WithAPIKey("dummy-key") |
||
28 | if err != nil { |
||
29 | t.Fatal(err) |
||
30 | } |
||
31 | |||
32 | var ctx context.Context |
||
33 | |||
34 | tests := []struct { |
||
35 | name string |
||
36 | want int |
||
37 | wantErr bool |
||
38 | err error |
||
39 | }{ |
||
40 | { |
||
41 | name: "test request is successful", |
||
42 | wantErr: false, |
||
43 | err: nil, |
||
44 | }, |
||
45 | } |
||
46 | |||
47 | for _, tt := range tests { |
||
48 | t.Run(tt.name, func(t *testing.T) { |
||
49 | _, err := testClient.Payments.List(ctx) |
||
50 | if tt.wantErr && err != nil { |
||
51 | if !reflect.DeepEqual(err, tt.err) { |
||
52 | t.Fatal(err) |
||
53 | } |
||
54 | } |
||
55 | |||
56 | if err != tt.err { |
||
57 | t.Errorf("wanted nil, got %+v", err) |
||
58 | } |
||
62 |