golift.io/starr@v1.0.0/lidarr/calendar_test.go (about) 1 package lidarr_test 2 3 import ( 4 "net/http" 5 "testing" 6 "time" 7 8 "github.com/stretchr/testify/assert" 9 "golift.io/starr" 10 "golift.io/starr/lidarr" 11 "golift.io/starr/starrtest" 12 ) 13 14 var testCalendarJSON = `{ 15 "title": "Mount Westmore", 16 "disambiguation": "", 17 "overview": "", 18 "artistId": 163, 19 "foreignAlbumId": "95b28969-3252-45a7-9e1b-b2d8f59eee45", 20 "monitored": true, 21 "anyReleaseOk": true, 22 "profileId": 3, 23 "duration": 3897000, 24 "albumType": "Album", 25 "secondaryTypes": [], 26 "mediumCount": 1, 27 "ratings": { 28 "votes": 0, 29 "value": 0 30 }, 31 "releaseDate": "2022-12-09T00:00:00Z", 32 "releases": [ 33 { 34 "id": 16428, 35 "albumId": 3722, 36 "foreignReleaseId": "c2db5e7b-9225-4d01-83bf-b6a4e8c36c02", 37 "title": "Mount Westmore", 38 "status": "Official", 39 "duration": 3897000, 40 "trackCount": 16, 41 "media": [ 42 { 43 "mediumNumber": 1, 44 "mediumName": "", 45 "mediumFormat": "Digital Media" 46 } 47 ], 48 "mediumCount": 1, 49 "disambiguation": "", 50 "country": [ 51 "[Worldwide]" 52 ], 53 "label": [ 54 "Mount Westmore, LLC" 55 ], 56 "format": "Digital Media", 57 "monitored": true 58 } 59 ], 60 "genres": [], 61 "media": [ 62 { 63 "mediumNumber": 1, 64 "mediumName": "", 65 "mediumFormat": "Digital Media" 66 } 67 ], 68 "images": [ 69 { 70 "url": "/lidarr/MediaCover/Albums/3722/cover.jpg?lastWrite=638062138360000000", 71 "coverType": "cover", 72 "extension": ".jpg", 73 "remoteUrl": "https://imagecache.lidarr.audio/v1/caa/c2db5e7b-9225-4d01-83bf-b6a4e8c36c02/34308803649-1200.jpg" 74 } 75 ], 76 "links": [], 77 "statistics": { 78 "trackFileCount": 0, 79 "trackCount": 16, 80 "totalTrackCount": 16, 81 "sizeOnDisk": 0, 82 "percentOfTracks": 0 83 }, 84 "grabbed": false, 85 "id": 3722 86 }` 87 88 // This matches the json above. 89 var testCalendarStruct = lidarr.Album{ 90 ID: 3722, 91 Title: "Mount Westmore", 92 ArtistID: 163, 93 ForeignAlbumID: "95b28969-3252-45a7-9e1b-b2d8f59eee45", 94 ProfileID: 3, 95 SecondaryTypes: []interface{}{}, 96 Duration: 3897000, 97 AlbumType: "Album", 98 MediumCount: 1, 99 Links: []*starr.Link{}, 100 Ratings: &starr.Ratings{Votes: 0, Value: 0}, 101 ReleaseDate: time.Date(2022, time.December, 9, 0, 0, 0, 0, time.UTC), 102 Media: []*lidarr.Media{{ 103 MediumNumber: 1, 104 MediumName: "", 105 MediumFormat: "Digital Media", 106 }}, 107 Releases: []*lidarr.Release{{ 108 ID: 16428, 109 AlbumID: 3722, 110 ForeignReleaseID: "c2db5e7b-9225-4d01-83bf-b6a4e8c36c02", 111 Title: "Mount Westmore", 112 Status: "Official", 113 Duration: 3897000, 114 TrackCount: 16, 115 Media: []*lidarr.Media{{ 116 MediumNumber: 1, 117 MediumName: "", 118 MediumFormat: "Digital Media", 119 }}, 120 MediumCount: 1, 121 Disambiguation: "", 122 Country: []string{"[Worldwide]"}, 123 Label: []string{"Mount Westmore, LLC"}, 124 Format: "Digital Media", 125 Monitored: true, 126 }}, 127 Genres: []string{}, 128 Images: []*starr.Image{ 129 { 130 URL: "/lidarr/MediaCover/Albums/3722/cover.jpg?lastWrite=638062138360000000", 131 CoverType: "cover", 132 Extension: ".jpg", 133 RemoteURL: "https://imagecache.lidarr.audio/v1/caa/c2db5e7b-9225-4d01-83bf-b6a4e8c36c02/34308803649-1200.jpg", 134 }, 135 }, 136 Statistics: &lidarr.Statistics{ 137 TrackFileCount: 0, 138 TrackCount: 16, 139 TotalTrackCount: 16, 140 SizeOnDisk: 0, 141 PercentOfTracks: 0, 142 }, 143 Monitored: true, 144 AnyReleaseOk: true, 145 Grabbed: false, 146 } 147 148 func TestGetCalendar(t *testing.T) { 149 t.Parallel() 150 151 tests := []*starrtest.MockData{ 152 { 153 Name: "200", 154 ExpectedPath: "/api/v1/calendar" + 155 "?end=2020-02-20T04%3A20%3A20.000Z" + 156 "&includeArtist=false" + 157 "&start=2020-02-20T04%3A20%3A20.000Z" + 158 "&unmonitored=true", 159 ResponseStatus: http.StatusOK, 160 ResponseBody: `[` + testCalendarJSON + `]`, 161 WithRequest: lidarr.Calendar{ 162 Start: time.Unix(1582172420, 0), 163 End: time.Unix(1582172420, 0), 164 Unmonitored: true, 165 IncludeArtist: false, 166 }, 167 WithError: nil, 168 ExpectedMethod: http.MethodGet, 169 WithResponse: []*lidarr.Album{&testCalendarStruct}, 170 }, 171 { 172 Name: "404", 173 ExpectedPath: "/api/v1/calendar" + 174 "?end=2020-02-20T04%3A20%3A20.000Z" + 175 "&includeArtist=false" + 176 "&start=2020-02-20T04%3A20%3A20.000Z" + 177 "&unmonitored=true", 178 ResponseStatus: http.StatusNotFound, 179 ResponseBody: `{"message": "NotFound"}`, 180 WithError: &starr.ReqError{Code: http.StatusNotFound}, 181 ExpectedMethod: http.MethodGet, 182 WithRequest: lidarr.Calendar{ 183 Start: time.Unix(1582172420, 0), 184 End: time.Unix(1582172420, 0), 185 Unmonitored: true, 186 }, 187 WithResponse: []*lidarr.Album(nil), 188 }, 189 } 190 191 for _, test := range tests { 192 test := test 193 t.Run(test.Name, func(t *testing.T) { 194 t.Parallel() 195 mockServer := test.GetMockServer(t) 196 client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0)) 197 output, err := client.GetCalendar(test.WithRequest.(lidarr.Calendar)) 198 assert.ErrorIs(t, err, test.WithError, "the wrong error was returned") 199 assert.EqualValues(t, test.WithResponse, output, "make sure ResponseBody and WithResponse are a match") 200 }) 201 } 202 } 203 204 func TestGetCalendarID(t *testing.T) { 205 t.Parallel() 206 207 tests := []*starrtest.MockData{ 208 { 209 Name: "200", 210 ExpectedPath: "/api/v1/calendar/1", 211 ResponseStatus: http.StatusOK, 212 ResponseBody: testCalendarJSON, 213 WithRequest: int64(1), 214 WithError: nil, 215 ExpectedMethod: http.MethodGet, 216 WithResponse: &testCalendarStruct, 217 }, 218 { 219 Name: "404", 220 ExpectedPath: "/api/v1/calendar/1", 221 ResponseStatus: http.StatusNotFound, 222 ResponseBody: `{"message": "NotFound"}`, 223 WithError: starr.ErrInvalidStatusCode, 224 ExpectedMethod: http.MethodGet, 225 WithRequest: int64(1), 226 WithResponse: (*lidarr.Album)(nil), 227 }, 228 } 229 230 for _, test := range tests { 231 test := test 232 t.Run(test.Name, func(t *testing.T) { 233 t.Parallel() 234 mockServer := test.GetMockServer(t) 235 client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0)) 236 output, err := client.GetCalendarID(test.WithRequest.(int64)) 237 assert.ErrorIs(t, err, test.WithError, "the wrong error was returned") 238 assert.EqualValues(t, test.WithResponse, output, "make sure ResponseBody and WithResponse are a match") 239 }) 240 } 241 }