|
| 1 | +package monstercat |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | +) |
| 8 | + |
| 9 | +func TestCatalog(t *testing.T) { |
| 10 | + client := NewClient() |
| 11 | + |
| 12 | + catalog, err := client.GetCatalog("", "", 10, 0) |
| 13 | + assert.NoError(t, err) |
| 14 | + assert.NotEmpty(t, catalog.Data) |
| 15 | + assert.NotEqual(t, 0, catalog.Total) |
| 16 | + assert.True(t, catalog.HasNextPage()) |
| 17 | +} |
| 18 | + |
| 19 | +func TestCatalog_Search(t *testing.T) { |
| 20 | + client := NewClient() |
| 21 | + |
| 22 | + catalog, err := client.GetCatalog("mix", "", 10, 0) |
| 23 | + assert.NoError(t, err) |
| 24 | + assert.NotEmpty(t, catalog.Data) |
| 25 | + assert.NotEqual(t, 0, catalog.Total) |
| 26 | + assert.True(t, catalog.HasNextPage()) |
| 27 | +} |
| 28 | + |
| 29 | +func TestCatalog_Search_NoResults(t *testing.T) { |
| 30 | + client := NewClient() |
| 31 | + |
| 32 | + catalog, err := client.GetCatalog("xxx not found xxx", "", 10, 0) |
| 33 | + assert.NoError(t, err) |
| 34 | + assert.Empty(t, catalog.Data) |
| 35 | + assert.Equal(t, 0, catalog.Total) |
| 36 | + assert.False(t, catalog.HasNextPage()) |
| 37 | +} |
| 38 | + |
| 39 | +func TestCatalog_Type(t *testing.T) { |
| 40 | + client := NewClient() |
| 41 | + |
| 42 | + catalog, err := client.GetCatalog("", string(ReleaseTypeSingle), 10, 0) |
| 43 | + assert.NoError(t, err) |
| 44 | + assert.NotEmpty(t, catalog.Data) |
| 45 | + assert.NotEqual(t, 0, catalog.Total) |
| 46 | + assert.True(t, catalog.HasNextPage()) |
| 47 | +} |
| 48 | + |
| 49 | +func TestCatalog_Type_NoResults(t *testing.T) { |
| 50 | + client := NewClient() |
| 51 | + |
| 52 | + catalog, err := client.GetCatalog("", "xxx not found", 10, 0) |
| 53 | + assert.NoError(t, err) |
| 54 | + assert.Empty(t, catalog.Data) |
| 55 | + assert.Equal(t, 0, catalog.Total) |
| 56 | + assert.False(t, catalog.HasNextPage()) |
| 57 | +} |
| 58 | + |
| 59 | +func TestCatalog_Search_Type(t *testing.T) { |
| 60 | + client := NewClient() |
| 61 | + |
| 62 | + catalog, err := client.GetCatalog("mix", string(ReleaseTypeCompilation), 5, 0) |
| 63 | + assert.NoError(t, err) |
| 64 | + assert.NotEmpty(t, catalog.Data) |
| 65 | + assert.NotEqual(t, 0, catalog.Total) |
| 66 | + assert.True(t, catalog.HasNextPage()) |
| 67 | +} |
| 68 | + |
| 69 | +func TestCatalogUntilEnd(t *testing.T) { |
| 70 | + client := NewClient() |
| 71 | + |
| 72 | + catalog, err := client.GetCatalog("", "", 100, 0) |
| 73 | + assert.NoError(t, err) |
| 74 | + |
| 75 | + for catalog.HasNextPage() { |
| 76 | + catalog, err = client.GetCatalog("", "", catalog.Limit, catalog.Offset+catalog.Limit) |
| 77 | + assert.NoError(t, err) |
| 78 | + } |
| 79 | +} |
0 commit comments