|
| 1 | +package account |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "net/http" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/sirupsen/logrus" |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | + "github.com/stretchr/testify/require" |
| 11 | + |
| 12 | + "github.com/KnutZuidema/golio/api" |
| 13 | + "github.com/KnutZuidema/golio/internal" |
| 14 | + "github.com/KnutZuidema/golio/internal/mock" |
| 15 | +) |
| 16 | + |
| 17 | +func TestAccountClient_GetByPUUID(t *testing.T) { |
| 18 | + t.Parallel() |
| 19 | + tests := []struct { |
| 20 | + name string |
| 21 | + want *Account |
| 22 | + doer internal.Doer |
| 23 | + wantErr error |
| 24 | + }{ |
| 25 | + { |
| 26 | + name: "get response", |
| 27 | + want: &Account{}, |
| 28 | + doer: mock.NewJSONMockDoer(Account{}, 200), |
| 29 | + }, |
| 30 | + { |
| 31 | + name: "not found", |
| 32 | + wantErr: api.ErrNotFound, |
| 33 | + doer: mock.NewStatusMockDoer(http.StatusNotFound), |
| 34 | + }, |
| 35 | + } |
| 36 | + for _, tt := range tests { |
| 37 | + t.Run( |
| 38 | + tt.name, func(t *testing.T) { |
| 39 | + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) |
| 40 | + got, err := (&Client{c: client}).GetByPUUID("") |
| 41 | + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) |
| 42 | + if tt.wantErr == nil { |
| 43 | + assert.Equal(t, got, tt.want) |
| 44 | + } |
| 45 | + }, |
| 46 | + ) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func TestAccountClient_GetByRiotID(t *testing.T) { |
| 51 | + t.Parallel() |
| 52 | + tests := []struct { |
| 53 | + name string |
| 54 | + want *Account |
| 55 | + doer internal.Doer |
| 56 | + wantErr error |
| 57 | + }{ |
| 58 | + { |
| 59 | + name: "get response", |
| 60 | + want: &Account{}, |
| 61 | + doer: mock.NewJSONMockDoer(Account{}, 200), |
| 62 | + }, |
| 63 | + { |
| 64 | + name: "not found", |
| 65 | + wantErr: api.ErrNotFound, |
| 66 | + doer: mock.NewStatusMockDoer(http.StatusNotFound), |
| 67 | + }, |
| 68 | + } |
| 69 | + for _, tt := range tests { |
| 70 | + t.Run( |
| 71 | + tt.name, func(t *testing.T) { |
| 72 | + client := internal.NewClient(api.RegionEuropeWest, "API_KEY", tt.doer, logrus.StandardLogger()) |
| 73 | + got, err := (&Client{c: client}).GetByRiotID("", "") |
| 74 | + require.Equal(t, err, tt.wantErr, fmt.Sprintf("want err %v, got %v", tt.wantErr, err)) |
| 75 | + if tt.wantErr == nil { |
| 76 | + assert.Equal(t, got, tt.want) |
| 77 | + } |
| 78 | + }, |
| 79 | + ) |
| 80 | + } |
| 81 | +} |
0 commit comments