golift.io/starr@v1.0.0/sonarr/series_test.go (about)

     1  package sonarr_test
     2  
     3  import (
     4  	"net/http"
     5  	"path"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"golift.io/starr"
    11  	"golift.io/starr/sonarr"
    12  	"golift.io/starr/starrtest"
    13  )
    14  
    15  const (
    16  	firstSeries = `{
    17  	"title": "Breaking Bad",
    18  	"alternateTitles": [],
    19  	"sortTitle": "breaking bad",
    20  	"status": "ended",
    21  	"ended": true,
    22  	"overview": "Cool teacher becomes drug dealer",
    23  	"previousAiring": "2019-06-04T01:00:00Z",
    24  	"network": "Netflix",
    25  	"airTime": "21:00",
    26  	"images": [
    27  		{
    28  			"coverType": "banner",
    29  			"url": "/MediaCover/1/banner.jpg?lastWrite=637829401993017870",
    30  			"remoteUrl": "https://artworks.thetvdb.com/banners/graphical/81189-g21.jpg"
    31  		},
    32  		{
    33  			"coverType": "poster",
    34  			"url": "/MediaCover/1/poster.jpg?lastWrite=637829401994817870",
    35  			"remoteUrl": "https://artworks.thetvdb.com/banners/posters/81189-10.jpg"
    36  		},
    37  		{
    38  			"coverType": "fanart",
    39  			"url": "/MediaCover/1/fanart.jpg?lastWrite=637829401996517870",
    40  			"remoteUrl": "https://artworks.thetvdb.com/banners/fanart/original/81189-21.jpg"
    41  		}
    42  	],
    43  	"seasons": [
    44  		{
    45  			"seasonNumber": 0,
    46  			"monitored": false,
    47  			"statistics": {
    48  				"episodeFileCount": 0,
    49  				"episodeCount": 0,
    50  				"totalEpisodeCount": 19,
    51  				"sizeOnDisk": 0,
    52  				"percentOfEpisodes": 0.0
    53  			}
    54  		},
    55  		{
    56  			"seasonNumber": 1,
    57  			"monitored": true,
    58  			"statistics": {
    59  				"previousAiring": "2019-06-04T01:00:00Z",
    60  				"episodeFileCount": 0,
    61  				"episodeCount": 7,
    62  				"totalEpisodeCount": 7,
    63  				"sizeOnDisk": 0,
    64  				"percentOfEpisodes": 0.0
    65  			}
    66  		},
    67  		{
    68  			"seasonNumber": 2,
    69  			"monitored": true,
    70  			"statistics": {
    71  				"previousAiring": "2019-06-04T01:00:00Z",
    72  				"episodeFileCount": 0,
    73  				"episodeCount": 13,
    74  				"totalEpisodeCount": 13,
    75  				"sizeOnDisk": 0,
    76  				"percentOfEpisodes": 0.0
    77  			}
    78  		},
    79  		{
    80  			"seasonNumber": 3,
    81  			"monitored": true,
    82  			"statistics": {
    83  				"previousAiring": "2019-06-04T01:00:00Z",
    84  				"episodeFileCount": 0,
    85  				"episodeCount": 13,
    86  				"totalEpisodeCount": 13,
    87  				"sizeOnDisk": 0,
    88  				"percentOfEpisodes": 0.0
    89  			}
    90  		},
    91  		{
    92  			"seasonNumber": 4,
    93  			"monitored": true,
    94  			"statistics": {
    95  				"previousAiring": "2019-06-04T01:00:00Z",
    96  				"episodeFileCount": 0,
    97  				"episodeCount": 13,
    98  				"totalEpisodeCount": 13,
    99  				"sizeOnDisk": 0,
   100  				"percentOfEpisodes": 0.0
   101  			}
   102  		},
   103  		{
   104  			"seasonNumber": 5,
   105  			"monitored": true,
   106  			"statistics": {
   107  				"previousAiring": "2019-06-04T01:00:00Z",
   108  				"episodeFileCount": 0,
   109  				"episodeCount": 16,
   110  				"totalEpisodeCount": 16,
   111  				"sizeOnDisk": 0,
   112  				"percentOfEpisodes": 0.0
   113  			}
   114  		}
   115  	],
   116  	"year": 2008,
   117  	"path": "/series/Breaking Bad",
   118  	"qualityProfileId": 1,
   119  	"languageProfileId": 1,
   120  	"seasonFolder": true,
   121  	"monitored": true,
   122  	"useSceneNumbering": false,
   123  	"runtime": 47,
   124  	"tvdbId": 81189,
   125  	"tvRageId": 18164,
   126  	"tvMazeId": 169,
   127  	"firstAired": "2019-06-04T01:00:00Z",
   128  	"seriesType": "standard",
   129  	"cleanTitle": "breakingbad",
   130  	"imdbId": "tt0903747",
   131  	"titleSlug": "breaking-bad",
   132  	"rootFolderPath": "/series/",
   133  	"certification": "TV-MA",
   134  	"genres": [
   135  		"Crime",
   136  		"Drama",
   137  		"Suspense",
   138  		"Thriller"
   139  	],
   140  	"tags": [
   141  		11
   142  	],
   143  	"added": "2019-06-04T01:00:00Z",
   144  	"ratings": {
   145  		"votes": 31714,
   146  		"value": 9.4
   147  	},
   148  	"statistics": {
   149  		"seasonCount": 5,
   150  		"episodeFileCount": 0,
   151  		"episodeCount": 62,
   152  		"totalEpisodeCount": 81,
   153  		"sizeOnDisk": 0,
   154  		"percentOfEpisodes": 0.0
   155  	},
   156  	"id": 1
   157  }`
   158  	secondSeries = `{
   159  	"title": "Chernobyl",
   160  	"alternateTitles": [],
   161  	"sortTitle": "chernobyl",
   162  	"status": "ended",
   163  	"ended": true,
   164  	"overview": "A lot of energy wasted",
   165  	"previousAiring": "2019-06-04T01:00:00Z",
   166  	"network": "HBO",
   167  	"airTime": "21:00",
   168  	"images": [
   169  		{
   170  			"coverType": "banner",
   171  			"url": "/MediaCover/2/banner.jpg?lastWrite=637829402715717870",
   172  			"remoteUrl": "https://artworks.thetvdb.com/banners/graphical/5cc9f74c2ddd3.jpg"
   173  		},
   174  		{
   175  			"coverType": "poster",
   176  			"url": "/MediaCover/2/poster.jpg?lastWrite=637829402718117870",
   177  			"remoteUrl": "https://artworks.thetvdb.com/banners/posters/5cc12861c93e4.jpg"
   178  		},
   179  		{
   180  			"coverType": "fanart",
   181  			"url": "/MediaCover/2/fanart.jpg?lastWrite=637829402721317870",
   182  			"remoteUrl": "https://artworks.thetvdb.com/banners/series/360893/backgrounds/62017319.jpg"
   183  		}
   184  	],
   185  	"seasons": [
   186  		{
   187  			"seasonNumber": 0,
   188  			"monitored": false,
   189  			"statistics": {
   190  				"episodeFileCount": 0,
   191  				"episodeCount": 0,
   192  				"totalEpisodeCount": 14,
   193  				"sizeOnDisk": 0,
   194  				"percentOfEpisodes": 0.0
   195  			}
   196  		},
   197  		{
   198  			"seasonNumber": 1,
   199  			"monitored": true,
   200  			"statistics": {
   201  				"previousAiring": "2019-06-04T01:00:00Z",
   202  				"episodeFileCount": 0,
   203  				"episodeCount": 5,
   204  				"totalEpisodeCount": 5,
   205  				"sizeOnDisk": 0,
   206  				"percentOfEpisodes": 0.0
   207  			}
   208  		}
   209  	],
   210  	"year": 2019,
   211  	"path": "/series/Chernobyl",
   212  	"qualityProfileId": 1,
   213  	"languageProfileId": 1,
   214  	"seasonFolder": true,
   215  	"monitored": true,
   216  	"useSceneNumbering": false,
   217  	"runtime": 65,
   218  	"tvdbId": 360893,
   219  	"tvRageId": 0,
   220  	"tvMazeId": 30770,
   221  	"firstAired": "2019-06-04T01:00:00Z",
   222  	"seriesType": "standard",
   223  	"cleanTitle": "chernobyl",
   224  	"imdbId": "tt7366338",
   225  	"titleSlug": "chernobyl",
   226  	"rootFolderPath": "/series/",
   227  	"certification": "TV-MA",
   228  	"genres": [
   229  		"Drama",
   230  		"History",
   231  		"Mini-Series",
   232  		"Thriller"
   233  	],
   234  	"tags": [
   235  		11
   236  	],
   237  	"added": "2019-06-04T01:00:00Z",
   238  	"ratings": {
   239  		"votes": 83,
   240  		"value": 8.7
   241  	},
   242  	"statistics": {
   243  		"seasonCount": 1,
   244  		"episodeFileCount": 0,
   245  		"episodeCount": 5,
   246  		"totalEpisodeCount": 19,
   247  		"sizeOnDisk": 0,
   248  		"percentOfEpisodes": 0.0
   249  	},
   250  	"id": 2
   251  }`
   252  	listSeries = `[` + firstSeries + `,` + secondSeries + `]`
   253  	addSeries  = `{"monitored":true,"seasonFolder":true,"languageProfileId":1,"qualityProfileId":1,` +
   254  		`"tvdbId":360893,"path":"/series/Chernobyl","title":"Chernobyl","titleSlug":"chernobyl",` +
   255  		`"rootFolderPath":"/series/","tags":[11],` +
   256  		`"seasons":[{"monitored":false,"seasonNumber":0},{"monitored":true,"seasonNumber":1}],` +
   257  		`"images":[{"coverType":"banner","remoteUrl":"https://artworks.thetvdb.com/banners/graphical/5cc9f74c2ddd3.jpg"},` +
   258  		`{"coverType":"poster","remoteUrl":"https://artworks.thetvdb.com/banners/posters/5cc12861c93e4.jpg"},` +
   259  		`{"coverType":"fanart","remoteUrl":"https://artworks.thetvdb.com/banners/series/360893/backgrounds/62017319.jpg"}],` +
   260  		`"addOptions":{"searchForMissingEpisodes":true}}` +
   261  		"\n"
   262  	updateSeries = `{"monitored":true,"seasonFolder":true,"id":1,"languageProfileId":1,"qualityProfileId":1,` +
   263  		`"tvdbId":360893,"path":"/series/Chernobyl","title":"Chernobyl","rootFolderPath":` +
   264  		`"/series/","tags":[11],"seasons":[{"monitored":false,"seasonNumber":0},{"monitored":true,"seasonNumber":1}]}` +
   265  		"\n"
   266  )
   267  
   268  func TestGetAllSeries(t *testing.T) {
   269  	t.Parallel()
   270  
   271  	loc, _ := time.LoadLocation("")
   272  	date := time.Date(2019, 6, 4, 1, 0, 0, 0, loc)
   273  
   274  	tests := []*starrtest.MockData{
   275  		{
   276  			Name:           "200",
   277  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "series"),
   278  			ExpectedMethod: "GET",
   279  			ResponseStatus: 200,
   280  			ResponseBody:   listSeries,
   281  			WithResponse: []*sonarr.Series{
   282  				{
   283  					Title:           "Breaking Bad",
   284  					AlternateTitles: []*sonarr.AlternateTitle{},
   285  					SortTitle:       "breaking bad",
   286  					Status:          "ended",
   287  					Ended:           true,
   288  					Overview:        "Cool teacher becomes drug dealer",
   289  					PreviousAiring:  date,
   290  					Network:         "Netflix",
   291  					AirTime:         "21:00",
   292  					Images: []*starr.Image{
   293  						{
   294  							CoverType: "banner",
   295  							URL:       "/MediaCover/1/banner.jpg?lastWrite=637829401993017870",
   296  							RemoteURL: "https://artworks.thetvdb.com/banners/graphical/81189-g21.jpg",
   297  						},
   298  						{
   299  							CoverType: "poster",
   300  							URL:       "/MediaCover/1/poster.jpg?lastWrite=637829401994817870",
   301  							RemoteURL: "https://artworks.thetvdb.com/banners/posters/81189-10.jpg",
   302  						},
   303  						{
   304  							CoverType: "fanart",
   305  							URL:       "/MediaCover/1/fanart.jpg?lastWrite=637829401996517870",
   306  							RemoteURL: "https://artworks.thetvdb.com/banners/fanart/original/81189-21.jpg",
   307  						},
   308  					},
   309  					Seasons: []*sonarr.Season{
   310  						{
   311  							SeasonNumber: 0,
   312  							Monitored:    false,
   313  							Statistics: &sonarr.Statistics{
   314  								EpisodeFileCount:  0,
   315  								EpisodeCount:      0,
   316  								TotalEpisodeCount: 19,
   317  								SizeOnDisk:        0,
   318  								PercentOfEpisodes: 0.0,
   319  							},
   320  						},
   321  						{
   322  							SeasonNumber: 1,
   323  							Monitored:    true,
   324  							Statistics: &sonarr.Statistics{
   325  								PreviousAiring:    date,
   326  								EpisodeFileCount:  0,
   327  								EpisodeCount:      7,
   328  								TotalEpisodeCount: 7,
   329  								SizeOnDisk:        0,
   330  								PercentOfEpisodes: 0.0,
   331  							},
   332  						},
   333  						{
   334  							SeasonNumber: 2,
   335  							Monitored:    true,
   336  							Statistics: &sonarr.Statistics{
   337  								PreviousAiring:    date,
   338  								EpisodeFileCount:  0,
   339  								EpisodeCount:      13,
   340  								TotalEpisodeCount: 13,
   341  								SizeOnDisk:        0,
   342  								PercentOfEpisodes: 0.0,
   343  							},
   344  						},
   345  						{
   346  							SeasonNumber: 3,
   347  							Monitored:    true,
   348  							Statistics: &sonarr.Statistics{
   349  								PreviousAiring:    date,
   350  								EpisodeFileCount:  0,
   351  								EpisodeCount:      13,
   352  								TotalEpisodeCount: 13,
   353  								SizeOnDisk:        0,
   354  								PercentOfEpisodes: 0.0,
   355  							},
   356  						},
   357  						{
   358  							SeasonNumber: 4,
   359  							Monitored:    true,
   360  							Statistics: &sonarr.Statistics{
   361  								PreviousAiring:    date,
   362  								EpisodeFileCount:  0,
   363  								EpisodeCount:      13,
   364  								TotalEpisodeCount: 13,
   365  								SizeOnDisk:        0,
   366  								PercentOfEpisodes: 0.0,
   367  							},
   368  						},
   369  						{
   370  							SeasonNumber: 5,
   371  							Monitored:    true,
   372  							Statistics: &sonarr.Statistics{
   373  								PreviousAiring:    date,
   374  								EpisodeFileCount:  0,
   375  								EpisodeCount:      16,
   376  								TotalEpisodeCount: 16,
   377  								SizeOnDisk:        0,
   378  								PercentOfEpisodes: 0.0,
   379  							},
   380  						},
   381  					},
   382  					Year:              2008,
   383  					Path:              "/series/Breaking Bad",
   384  					QualityProfileID:  1,
   385  					LanguageProfileID: 1,
   386  					SeasonFolder:      true,
   387  					Monitored:         true,
   388  					UseSceneNumbering: false,
   389  					Runtime:           47,
   390  					TvdbID:            81189,
   391  					TvRageID:          18164,
   392  					TvMazeID:          169,
   393  					FirstAired:        date,
   394  					SeriesType:        "standard",
   395  					CleanTitle:        "breakingbad",
   396  					ImdbID:            "tt0903747",
   397  					TitleSlug:         "breaking-bad",
   398  					RootFolderPath:    "/series/",
   399  					Certification:     "TV-MA",
   400  					Genres: []string{
   401  						"Crime",
   402  						"Drama",
   403  						"Suspense",
   404  						"Thriller",
   405  					},
   406  					Tags: []int{
   407  						11,
   408  					},
   409  					Added: date,
   410  					Ratings: &starr.Ratings{
   411  						Votes: 31714,
   412  						Value: 9.4,
   413  					},
   414  					Statistics: &sonarr.Statistics{
   415  						SeasonCount:       5,
   416  						EpisodeFileCount:  0,
   417  						EpisodeCount:      62,
   418  						TotalEpisodeCount: 81,
   419  						SizeOnDisk:        0,
   420  						PercentOfEpisodes: 0.0,
   421  					},
   422  					ID: 1,
   423  				},
   424  				{
   425  					Title:           "Chernobyl",
   426  					AlternateTitles: []*sonarr.AlternateTitle{},
   427  					SortTitle:       "chernobyl",
   428  					Status:          "ended",
   429  					Ended:           true,
   430  					Overview:        "A lot of energy wasted",
   431  					PreviousAiring:  date,
   432  					Network:         "HBO",
   433  					AirTime:         "21:00",
   434  					Images: []*starr.Image{
   435  						{
   436  							CoverType: "banner",
   437  							URL:       "/MediaCover/2/banner.jpg?lastWrite=637829402715717870",
   438  							RemoteURL: "https://artworks.thetvdb.com/banners/graphical/5cc9f74c2ddd3.jpg",
   439  						},
   440  						{
   441  							CoverType: "poster",
   442  							URL:       "/MediaCover/2/poster.jpg?lastWrite=637829402718117870",
   443  							RemoteURL: "https://artworks.thetvdb.com/banners/posters/5cc12861c93e4.jpg",
   444  						},
   445  						{
   446  							CoverType: "fanart",
   447  							URL:       "/MediaCover/2/fanart.jpg?lastWrite=637829402721317870",
   448  							RemoteURL: "https://artworks.thetvdb.com/banners/series/360893/backgrounds/62017319.jpg",
   449  						},
   450  					},
   451  					Seasons: []*sonarr.Season{
   452  						{
   453  							SeasonNumber: 0,
   454  							Monitored:    false,
   455  							Statistics: &sonarr.Statistics{
   456  								EpisodeFileCount:  0,
   457  								EpisodeCount:      0,
   458  								TotalEpisodeCount: 14,
   459  								SizeOnDisk:        0,
   460  								PercentOfEpisodes: 0.0,
   461  							},
   462  						},
   463  						{
   464  							SeasonNumber: 1,
   465  							Monitored:    true,
   466  							Statistics: &sonarr.Statistics{
   467  								PreviousAiring:    date,
   468  								EpisodeFileCount:  0,
   469  								EpisodeCount:      5,
   470  								TotalEpisodeCount: 5,
   471  								SizeOnDisk:        0,
   472  								PercentOfEpisodes: 0.0,
   473  							},
   474  						},
   475  					},
   476  					Year:              2019,
   477  					Path:              "/series/Chernobyl",
   478  					QualityProfileID:  1,
   479  					LanguageProfileID: 1,
   480  					SeasonFolder:      true,
   481  					Monitored:         true,
   482  					UseSceneNumbering: false,
   483  					Runtime:           65,
   484  					TvdbID:            360893,
   485  					TvRageID:          0,
   486  					TvMazeID:          30770,
   487  					FirstAired:        date,
   488  					SeriesType:        "standard",
   489  					CleanTitle:        "chernobyl",
   490  					ImdbID:            "tt7366338",
   491  					TitleSlug:         "chernobyl",
   492  					RootFolderPath:    "/series/",
   493  					Certification:     "TV-MA",
   494  					Genres: []string{
   495  						"Drama",
   496  						"History",
   497  						"Mini-Series",
   498  						"Thriller",
   499  					},
   500  					Tags: []int{
   501  						11,
   502  					},
   503  					Added: date,
   504  					Ratings: &starr.Ratings{
   505  						Votes: 83,
   506  						Value: 8.7,
   507  					},
   508  					Statistics: &sonarr.Statistics{
   509  						SeasonCount:       1,
   510  						EpisodeFileCount:  0,
   511  						EpisodeCount:      5,
   512  						TotalEpisodeCount: 19,
   513  						SizeOnDisk:        0,
   514  						PercentOfEpisodes: 0.0,
   515  					},
   516  					ID: 2,
   517  				},
   518  			},
   519  			WithError: nil,
   520  		},
   521  		{
   522  			Name:           "404",
   523  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "series"),
   524  			ExpectedMethod: "GET",
   525  			ResponseStatus: 404,
   526  			ResponseBody:   starrtest.BodyNotFound,
   527  			WithError:      &starr.ReqError{Code: http.StatusNotFound},
   528  			WithResponse:   []*sonarr.Series(nil),
   529  		},
   530  	}
   531  
   532  	for _, test := range tests {
   533  		test := test
   534  		t.Run(test.Name, func(t *testing.T) {
   535  			t.Parallel()
   536  			mockServer := test.GetMockServer(t)
   537  			client := sonarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
   538  			output, err := client.GetAllSeries()
   539  			assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
   540  			assert.EqualValues(t, output, test.WithResponse, "response is not the same as expected")
   541  		})
   542  	}
   543  }
   544  
   545  func TestGetSeries(t *testing.T) {
   546  	t.Parallel()
   547  
   548  	loc, _ := time.LoadLocation("")
   549  	date := time.Date(2019, 6, 4, 1, 0, 0, 0, loc)
   550  
   551  	tests := []*starrtest.MockData{
   552  		{
   553  			Name:           "200",
   554  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "series?tvdbId=360893"),
   555  			ExpectedMethod: "GET",
   556  			ResponseStatus: 200,
   557  			ResponseBody:   "[" + secondSeries + "]",
   558  			WithRequest:    360893,
   559  			WithResponse: []*sonarr.Series{
   560  				{
   561  					Title:           "Chernobyl",
   562  					AlternateTitles: []*sonarr.AlternateTitle{},
   563  					SortTitle:       "chernobyl",
   564  					Status:          "ended",
   565  					Ended:           true,
   566  					Overview:        "A lot of energy wasted",
   567  					PreviousAiring:  date,
   568  					Network:         "HBO",
   569  					AirTime:         "21:00",
   570  					Images: []*starr.Image{
   571  						{
   572  							CoverType: "banner",
   573  							URL:       "/MediaCover/2/banner.jpg?lastWrite=637829402715717870",
   574  							RemoteURL: "https://artworks.thetvdb.com/banners/graphical/5cc9f74c2ddd3.jpg",
   575  						},
   576  						{
   577  							CoverType: "poster",
   578  							URL:       "/MediaCover/2/poster.jpg?lastWrite=637829402718117870",
   579  							RemoteURL: "https://artworks.thetvdb.com/banners/posters/5cc12861c93e4.jpg",
   580  						},
   581  						{
   582  							CoverType: "fanart",
   583  							URL:       "/MediaCover/2/fanart.jpg?lastWrite=637829402721317870",
   584  							RemoteURL: "https://artworks.thetvdb.com/banners/series/360893/backgrounds/62017319.jpg",
   585  						},
   586  					},
   587  					Seasons: []*sonarr.Season{
   588  						{
   589  							SeasonNumber: 0,
   590  							Monitored:    false,
   591  							Statistics: &sonarr.Statistics{
   592  								EpisodeFileCount:  0,
   593  								EpisodeCount:      0,
   594  								TotalEpisodeCount: 14,
   595  								SizeOnDisk:        0,
   596  								PercentOfEpisodes: 0.0,
   597  							},
   598  						},
   599  						{
   600  							SeasonNumber: 1,
   601  							Monitored:    true,
   602  							Statistics: &sonarr.Statistics{
   603  								PreviousAiring:    date,
   604  								EpisodeFileCount:  0,
   605  								EpisodeCount:      5,
   606  								TotalEpisodeCount: 5,
   607  								SizeOnDisk:        0,
   608  								PercentOfEpisodes: 0.0,
   609  							},
   610  						},
   611  					},
   612  					Year:              2019,
   613  					Path:              "/series/Chernobyl",
   614  					QualityProfileID:  1,
   615  					LanguageProfileID: 1,
   616  					SeasonFolder:      true,
   617  					Monitored:         true,
   618  					UseSceneNumbering: false,
   619  					Runtime:           65,
   620  					TvdbID:            360893,
   621  					TvRageID:          0,
   622  					TvMazeID:          30770,
   623  					FirstAired:        date,
   624  					SeriesType:        "standard",
   625  					CleanTitle:        "chernobyl",
   626  					ImdbID:            "tt7366338",
   627  					TitleSlug:         "chernobyl",
   628  					RootFolderPath:    "/series/",
   629  					Certification:     "TV-MA",
   630  					Genres: []string{
   631  						"Drama",
   632  						"History",
   633  						"Mini-Series",
   634  						"Thriller",
   635  					},
   636  					Tags: []int{
   637  						11,
   638  					},
   639  					Added: date,
   640  					Ratings: &starr.Ratings{
   641  						Votes: 83,
   642  						Value: 8.7,
   643  					},
   644  					Statistics: &sonarr.Statistics{
   645  						SeasonCount:       1,
   646  						EpisodeFileCount:  0,
   647  						EpisodeCount:      5,
   648  						TotalEpisodeCount: 19,
   649  						SizeOnDisk:        0,
   650  						PercentOfEpisodes: 0.0,
   651  					},
   652  					ID: 2,
   653  				},
   654  			},
   655  			WithError: nil,
   656  		},
   657  		{
   658  			Name:           "404",
   659  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "series?tvdbId=360893"),
   660  			ExpectedMethod: "GET",
   661  			ResponseStatus: 404,
   662  			ResponseBody:   starrtest.BodyNotFound,
   663  			WithRequest:    360893,
   664  			WithError:      &starr.ReqError{Code: http.StatusNotFound},
   665  			WithResponse:   []*sonarr.Series(nil),
   666  		},
   667  	}
   668  
   669  	for _, test := range tests {
   670  		test := test
   671  		t.Run(test.Name, func(t *testing.T) {
   672  			t.Parallel()
   673  			mockServer := test.GetMockServer(t)
   674  			client := sonarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
   675  			output, err := client.GetSeries(int64(test.WithRequest.(int)))
   676  			assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
   677  			assert.EqualValues(t, output, test.WithResponse, "response is not the same as expected")
   678  		})
   679  	}
   680  }
   681  
   682  func TestGetSeriesByID(t *testing.T) {
   683  	t.Parallel()
   684  
   685  	loc, _ := time.LoadLocation("")
   686  	date := time.Date(2019, 6, 4, 1, 0, 0, 0, loc)
   687  
   688  	tests := []*starrtest.MockData{
   689  		{
   690  			Name:           "200",
   691  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "series", "2"),
   692  			ExpectedMethod: "GET",
   693  			ResponseStatus: 200,
   694  			ResponseBody:   secondSeries,
   695  			WithRequest:    2,
   696  			WithResponse: &sonarr.Series{
   697  				Title:           "Chernobyl",
   698  				AlternateTitles: []*sonarr.AlternateTitle{},
   699  				SortTitle:       "chernobyl",
   700  				Status:          "ended",
   701  				Ended:           true,
   702  				Overview:        "A lot of energy wasted",
   703  				PreviousAiring:  date,
   704  				Network:         "HBO",
   705  				AirTime:         "21:00",
   706  				Images: []*starr.Image{
   707  					{
   708  						CoverType: "banner",
   709  						URL:       "/MediaCover/2/banner.jpg?lastWrite=637829402715717870",
   710  						RemoteURL: "https://artworks.thetvdb.com/banners/graphical/5cc9f74c2ddd3.jpg",
   711  					},
   712  					{
   713  						CoverType: "poster",
   714  						URL:       "/MediaCover/2/poster.jpg?lastWrite=637829402718117870",
   715  						RemoteURL: "https://artworks.thetvdb.com/banners/posters/5cc12861c93e4.jpg",
   716  					},
   717  					{
   718  						CoverType: "fanart",
   719  						URL:       "/MediaCover/2/fanart.jpg?lastWrite=637829402721317870",
   720  						RemoteURL: "https://artworks.thetvdb.com/banners/series/360893/backgrounds/62017319.jpg",
   721  					},
   722  				},
   723  				Seasons: []*sonarr.Season{
   724  					{
   725  						SeasonNumber: 0,
   726  						Monitored:    false,
   727  						Statistics: &sonarr.Statistics{
   728  							EpisodeFileCount:  0,
   729  							EpisodeCount:      0,
   730  							TotalEpisodeCount: 14,
   731  							SizeOnDisk:        0,
   732  							PercentOfEpisodes: 0.0,
   733  						},
   734  					},
   735  					{
   736  						SeasonNumber: 1,
   737  						Monitored:    true,
   738  						Statistics: &sonarr.Statistics{
   739  							PreviousAiring:    date,
   740  							EpisodeFileCount:  0,
   741  							EpisodeCount:      5,
   742  							TotalEpisodeCount: 5,
   743  							SizeOnDisk:        0,
   744  							PercentOfEpisodes: 0.0,
   745  						},
   746  					},
   747  				},
   748  				Year:              2019,
   749  				Path:              "/series/Chernobyl",
   750  				QualityProfileID:  1,
   751  				LanguageProfileID: 1,
   752  				SeasonFolder:      true,
   753  				Monitored:         true,
   754  				UseSceneNumbering: false,
   755  				Runtime:           65,
   756  				TvdbID:            360893,
   757  				TvRageID:          0,
   758  				TvMazeID:          30770,
   759  				FirstAired:        date,
   760  				SeriesType:        "standard",
   761  				CleanTitle:        "chernobyl",
   762  				ImdbID:            "tt7366338",
   763  				TitleSlug:         "chernobyl",
   764  				RootFolderPath:    "/series/",
   765  				Certification:     "TV-MA",
   766  				Genres: []string{
   767  					"Drama",
   768  					"History",
   769  					"Mini-Series",
   770  					"Thriller",
   771  				},
   772  				Tags: []int{
   773  					11,
   774  				},
   775  				Added: date,
   776  				Ratings: &starr.Ratings{
   777  					Votes: 83,
   778  					Value: 8.7,
   779  				},
   780  				Statistics: &sonarr.Statistics{
   781  					SeasonCount:       1,
   782  					EpisodeFileCount:  0,
   783  					EpisodeCount:      5,
   784  					TotalEpisodeCount: 19,
   785  					SizeOnDisk:        0,
   786  					PercentOfEpisodes: 0.0,
   787  				},
   788  				ID: 2,
   789  			},
   790  			WithError: nil,
   791  		},
   792  		{
   793  			Name:           "404",
   794  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "series", "2"),
   795  			ExpectedMethod: "GET",
   796  			ResponseStatus: 404,
   797  			ResponseBody:   starrtest.BodyNotFound,
   798  			WithRequest:    2,
   799  			WithError:      &starr.ReqError{Code: http.StatusNotFound},
   800  			WithResponse:   (*sonarr.Series)(nil),
   801  		},
   802  	}
   803  
   804  	for _, test := range tests {
   805  		test := test
   806  		t.Run(test.Name, func(t *testing.T) {
   807  			t.Parallel()
   808  			mockServer := test.GetMockServer(t)
   809  			client := sonarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
   810  			output, err := client.GetSeriesByID(int64(test.WithRequest.(int)))
   811  			assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
   812  			assert.EqualValues(t, output, test.WithResponse, "response is not the same as expected")
   813  		})
   814  	}
   815  }
   816  
   817  func TestAddSeries(t *testing.T) {
   818  	t.Parallel()
   819  
   820  	loc, _ := time.LoadLocation("")
   821  	date := time.Date(2019, 6, 4, 1, 0, 0, 0, loc)
   822  
   823  	tests := []*starrtest.MockData{
   824  		{
   825  			Name:            "200",
   826  			ExpectedPath:    path.Join("/", starr.API, sonarr.APIver, "series"),
   827  			ExpectedMethod:  "POST",
   828  			ExpectedRequest: addSeries,
   829  			ResponseStatus:  200,
   830  			WithRequest: &sonarr.AddSeriesInput{
   831  				Title: "Chernobyl",
   832  				Images: []*starr.Image{
   833  					{
   834  						CoverType: "banner",
   835  						RemoteURL: "https://artworks.thetvdb.com/banners/graphical/5cc9f74c2ddd3.jpg",
   836  					},
   837  					{
   838  						CoverType: "poster",
   839  						RemoteURL: "https://artworks.thetvdb.com/banners/posters/5cc12861c93e4.jpg",
   840  					},
   841  					{
   842  						CoverType: "fanart",
   843  						RemoteURL: "https://artworks.thetvdb.com/banners/series/360893/backgrounds/62017319.jpg",
   844  					},
   845  				},
   846  				Seasons: []*sonarr.Season{
   847  					{
   848  						SeasonNumber: 0,
   849  						Monitored:    false,
   850  					},
   851  					{
   852  						SeasonNumber: 1,
   853  						Monitored:    true,
   854  					},
   855  				},
   856  				Path:              "/series/Chernobyl",
   857  				QualityProfileID:  1,
   858  				LanguageProfileID: 1,
   859  				SeasonFolder:      true,
   860  				Monitored:         true,
   861  				TvdbID:            360893,
   862  				TitleSlug:         "chernobyl",
   863  				RootFolderPath:    "/series/",
   864  				Tags: []int{
   865  					11,
   866  				},
   867  				AddOptions: &sonarr.AddSeriesOptions{
   868  					SearchForMissingEpisodes: true,
   869  				},
   870  			},
   871  			ResponseBody: secondSeries,
   872  			WithResponse: &sonarr.Series{
   873  				Title:           "Chernobyl",
   874  				AlternateTitles: []*sonarr.AlternateTitle{},
   875  				SortTitle:       "chernobyl",
   876  				Status:          "ended",
   877  				Ended:           true,
   878  				Overview:        "A lot of energy wasted",
   879  				PreviousAiring:  date,
   880  				Network:         "HBO",
   881  				AirTime:         "21:00",
   882  				Images: []*starr.Image{
   883  					{
   884  						CoverType: "banner",
   885  						URL:       "/MediaCover/2/banner.jpg?lastWrite=637829402715717870",
   886  						RemoteURL: "https://artworks.thetvdb.com/banners/graphical/5cc9f74c2ddd3.jpg",
   887  					},
   888  					{
   889  						CoverType: "poster",
   890  						URL:       "/MediaCover/2/poster.jpg?lastWrite=637829402718117870",
   891  						RemoteURL: "https://artworks.thetvdb.com/banners/posters/5cc12861c93e4.jpg",
   892  					},
   893  					{
   894  						CoverType: "fanart",
   895  						URL:       "/MediaCover/2/fanart.jpg?lastWrite=637829402721317870",
   896  						RemoteURL: "https://artworks.thetvdb.com/banners/series/360893/backgrounds/62017319.jpg",
   897  					},
   898  				},
   899  				Seasons: []*sonarr.Season{
   900  					{
   901  						SeasonNumber: 0,
   902  						Monitored:    false,
   903  						Statistics: &sonarr.Statistics{
   904  							EpisodeFileCount:  0,
   905  							EpisodeCount:      0,
   906  							TotalEpisodeCount: 14,
   907  							SizeOnDisk:        0,
   908  							PercentOfEpisodes: 0.0,
   909  						},
   910  					},
   911  					{
   912  						SeasonNumber: 1,
   913  						Monitored:    true,
   914  						Statistics: &sonarr.Statistics{
   915  							PreviousAiring:    date,
   916  							EpisodeFileCount:  0,
   917  							EpisodeCount:      5,
   918  							TotalEpisodeCount: 5,
   919  							SizeOnDisk:        0,
   920  							PercentOfEpisodes: 0.0,
   921  						},
   922  					},
   923  				},
   924  				Year:              2019,
   925  				Path:              "/series/Chernobyl",
   926  				QualityProfileID:  1,
   927  				LanguageProfileID: 1,
   928  				SeasonFolder:      true,
   929  				Monitored:         true,
   930  				UseSceneNumbering: false,
   931  				Runtime:           65,
   932  				TvdbID:            360893,
   933  				TvRageID:          0,
   934  				TvMazeID:          30770,
   935  				FirstAired:        date,
   936  				SeriesType:        "standard",
   937  				CleanTitle:        "chernobyl",
   938  				ImdbID:            "tt7366338",
   939  				TitleSlug:         "chernobyl",
   940  				RootFolderPath:    "/series/",
   941  				Certification:     "TV-MA",
   942  				Genres: []string{
   943  					"Drama",
   944  					"History",
   945  					"Mini-Series",
   946  					"Thriller",
   947  				},
   948  				Tags: []int{
   949  					11,
   950  				},
   951  				Added: date,
   952  				Ratings: &starr.Ratings{
   953  					Votes: 83,
   954  					Value: 8.7,
   955  				},
   956  				Statistics: &sonarr.Statistics{
   957  					SeasonCount:       1,
   958  					EpisodeFileCount:  0,
   959  					EpisodeCount:      5,
   960  					TotalEpisodeCount: 19,
   961  					SizeOnDisk:        0,
   962  					PercentOfEpisodes: 0.0,
   963  				},
   964  				ID: 2,
   965  			},
   966  			WithError: nil,
   967  		},
   968  		{
   969  			Name:            "404",
   970  			ExpectedPath:    path.Join("/", starr.API, sonarr.APIver, "series"),
   971  			ExpectedMethod:  "POST",
   972  			ExpectedRequest: addSeries,
   973  			ResponseStatus:  404,
   974  			WithRequest: &sonarr.AddSeriesInput{
   975  				Title: "Chernobyl",
   976  				Images: []*starr.Image{
   977  					{
   978  						CoverType: "banner",
   979  						RemoteURL: "https://artworks.thetvdb.com/banners/graphical/5cc9f74c2ddd3.jpg",
   980  					},
   981  					{
   982  						CoverType: "poster",
   983  						RemoteURL: "https://artworks.thetvdb.com/banners/posters/5cc12861c93e4.jpg",
   984  					},
   985  					{
   986  						CoverType: "fanart",
   987  						RemoteURL: "https://artworks.thetvdb.com/banners/series/360893/backgrounds/62017319.jpg",
   988  					},
   989  				},
   990  				Seasons: []*sonarr.Season{
   991  					{
   992  						SeasonNumber: 0,
   993  						Monitored:    false,
   994  					},
   995  					{
   996  						SeasonNumber: 1,
   997  						Monitored:    true,
   998  					},
   999  				},
  1000  				Path:              "/series/Chernobyl",
  1001  				QualityProfileID:  1,
  1002  				LanguageProfileID: 1,
  1003  				SeasonFolder:      true,
  1004  				Monitored:         true,
  1005  				TvdbID:            360893,
  1006  				TitleSlug:         "chernobyl",
  1007  				RootFolderPath:    "/series/",
  1008  				Tags: []int{
  1009  					11,
  1010  				},
  1011  				AddOptions: &sonarr.AddSeriesOptions{
  1012  					SearchForMissingEpisodes: true,
  1013  				},
  1014  			},
  1015  			ResponseBody: starrtest.BodyNotFound,
  1016  			WithError:    &starr.ReqError{Code: http.StatusNotFound},
  1017  			WithResponse: (*sonarr.Series)(nil),
  1018  		},
  1019  	}
  1020  
  1021  	for _, test := range tests {
  1022  		test := test
  1023  		t.Run(test.Name, func(t *testing.T) {
  1024  			t.Parallel()
  1025  			mockServer := test.GetMockServer(t)
  1026  			client := sonarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
  1027  			output, err := client.AddSeries(test.WithRequest.(*sonarr.AddSeriesInput))
  1028  			assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
  1029  			assert.EqualValues(t, output, test.WithResponse, "response is not the same as expected")
  1030  		})
  1031  	}
  1032  }
  1033  
  1034  func TestUpdateSeries(t *testing.T) {
  1035  	t.Parallel()
  1036  
  1037  	loc, _ := time.LoadLocation("")
  1038  	date := time.Date(2019, 6, 4, 1, 0, 0, 0, loc)
  1039  
  1040  	tests := []*starrtest.MockData{
  1041  		{
  1042  			Name:            "200",
  1043  			ExpectedPath:    path.Join("/", starr.API, sonarr.APIver, "series/1?moveFiles=false"),
  1044  			ExpectedMethod:  "PUT",
  1045  			ExpectedRequest: updateSeries,
  1046  			ResponseStatus:  200,
  1047  			WithRequest: &sonarr.AddSeriesInput{
  1048  				Title: "Chernobyl",
  1049  				Seasons: []*sonarr.Season{
  1050  					{
  1051  						SeasonNumber: 0,
  1052  						Monitored:    false,
  1053  					},
  1054  					{
  1055  						SeasonNumber: 1,
  1056  						Monitored:    true,
  1057  					},
  1058  				},
  1059  				Path:              "/series/Chernobyl",
  1060  				QualityProfileID:  1,
  1061  				LanguageProfileID: 1,
  1062  				SeasonFolder:      true,
  1063  				Monitored:         true,
  1064  				TvdbID:            360893,
  1065  				RootFolderPath:    "/series/",
  1066  				Tags: []int{
  1067  					11,
  1068  				},
  1069  				ID: 1,
  1070  			},
  1071  			ResponseBody: secondSeries,
  1072  			WithResponse: &sonarr.Series{
  1073  				Title:           "Chernobyl",
  1074  				AlternateTitles: []*sonarr.AlternateTitle{},
  1075  				SortTitle:       "chernobyl",
  1076  				Status:          "ended",
  1077  				Ended:           true,
  1078  				Overview:        "A lot of energy wasted",
  1079  				PreviousAiring:  date,
  1080  				Network:         "HBO",
  1081  				AirTime:         "21:00",
  1082  				Images: []*starr.Image{
  1083  					{
  1084  						CoverType: "banner",
  1085  						URL:       "/MediaCover/2/banner.jpg?lastWrite=637829402715717870",
  1086  						RemoteURL: "https://artworks.thetvdb.com/banners/graphical/5cc9f74c2ddd3.jpg",
  1087  					},
  1088  					{
  1089  						CoverType: "poster",
  1090  						URL:       "/MediaCover/2/poster.jpg?lastWrite=637829402718117870",
  1091  						RemoteURL: "https://artworks.thetvdb.com/banners/posters/5cc12861c93e4.jpg",
  1092  					},
  1093  					{
  1094  						CoverType: "fanart",
  1095  						URL:       "/MediaCover/2/fanart.jpg?lastWrite=637829402721317870",
  1096  						RemoteURL: "https://artworks.thetvdb.com/banners/series/360893/backgrounds/62017319.jpg",
  1097  					},
  1098  				},
  1099  				Seasons: []*sonarr.Season{
  1100  					{
  1101  						SeasonNumber: 0,
  1102  						Monitored:    false,
  1103  						Statistics: &sonarr.Statistics{
  1104  							EpisodeFileCount:  0,
  1105  							EpisodeCount:      0,
  1106  							TotalEpisodeCount: 14,
  1107  							SizeOnDisk:        0,
  1108  							PercentOfEpisodes: 0.0,
  1109  						},
  1110  					},
  1111  					{
  1112  						SeasonNumber: 1,
  1113  						Monitored:    true,
  1114  						Statistics: &sonarr.Statistics{
  1115  							PreviousAiring:    date,
  1116  							EpisodeFileCount:  0,
  1117  							EpisodeCount:      5,
  1118  							TotalEpisodeCount: 5,
  1119  							SizeOnDisk:        0,
  1120  							PercentOfEpisodes: 0.0,
  1121  						},
  1122  					},
  1123  				},
  1124  				Year:              2019,
  1125  				Path:              "/series/Chernobyl",
  1126  				QualityProfileID:  1,
  1127  				LanguageProfileID: 1,
  1128  				SeasonFolder:      true,
  1129  				Monitored:         true,
  1130  				UseSceneNumbering: false,
  1131  				Runtime:           65,
  1132  				TvdbID:            360893,
  1133  				TvRageID:          0,
  1134  				TvMazeID:          30770,
  1135  				FirstAired:        date,
  1136  				SeriesType:        "standard",
  1137  				CleanTitle:        "chernobyl",
  1138  				ImdbID:            "tt7366338",
  1139  				TitleSlug:         "chernobyl",
  1140  				RootFolderPath:    "/series/",
  1141  				Certification:     "TV-MA",
  1142  				Genres: []string{
  1143  					"Drama",
  1144  					"History",
  1145  					"Mini-Series",
  1146  					"Thriller",
  1147  				},
  1148  				Tags: []int{
  1149  					11,
  1150  				},
  1151  				Added: date,
  1152  				Ratings: &starr.Ratings{
  1153  					Votes: 83,
  1154  					Value: 8.7,
  1155  				},
  1156  				Statistics: &sonarr.Statistics{
  1157  					SeasonCount:       1,
  1158  					EpisodeFileCount:  0,
  1159  					EpisodeCount:      5,
  1160  					TotalEpisodeCount: 19,
  1161  					SizeOnDisk:        0,
  1162  					PercentOfEpisodes: 0.0,
  1163  				},
  1164  				ID: 2,
  1165  			},
  1166  			WithError: nil,
  1167  		},
  1168  		{
  1169  			Name:            "404",
  1170  			ExpectedPath:    path.Join("/", starr.API, sonarr.APIver, "series/1?moveFiles=false"),
  1171  			ExpectedMethod:  "PUT",
  1172  			ExpectedRequest: updateSeries,
  1173  			ResponseStatus:  404,
  1174  			WithRequest: &sonarr.AddSeriesInput{
  1175  				Title: "Chernobyl",
  1176  				Seasons: []*sonarr.Season{
  1177  					{
  1178  						SeasonNumber: 0,
  1179  						Monitored:    false,
  1180  					},
  1181  					{
  1182  						SeasonNumber: 1,
  1183  						Monitored:    true,
  1184  					},
  1185  				},
  1186  				Path:              "/series/Chernobyl",
  1187  				QualityProfileID:  1,
  1188  				LanguageProfileID: 1,
  1189  				SeasonFolder:      true,
  1190  				Monitored:         true,
  1191  				TvdbID:            360893,
  1192  				RootFolderPath:    "/series/",
  1193  				Tags: []int{
  1194  					11,
  1195  				},
  1196  				ID: 1,
  1197  			},
  1198  			ResponseBody: starrtest.BodyNotFound,
  1199  			WithError:    &starr.ReqError{Code: http.StatusNotFound},
  1200  			WithResponse: (*sonarr.Series)(nil),
  1201  		},
  1202  	}
  1203  
  1204  	for _, test := range tests {
  1205  		test := test
  1206  		t.Run(test.Name, func(t *testing.T) {
  1207  			t.Parallel()
  1208  			mockServer := test.GetMockServer(t)
  1209  			client := sonarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
  1210  			output, err := client.UpdateSeries(test.WithRequest.(*sonarr.AddSeriesInput), false)
  1211  			assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
  1212  			assert.EqualValues(t, output, test.WithResponse, "response is not the same as expected")
  1213  		})
  1214  	}
  1215  }
  1216  
  1217  func TestDeleteSeries(t *testing.T) {
  1218  	t.Parallel()
  1219  
  1220  	tests := []*starrtest.MockData{
  1221  		{
  1222  			Name:           "200",
  1223  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "series/2?addImportListExclusion=false&deleteFiles=true"),
  1224  			ExpectedMethod: "DELETE",
  1225  			ResponseStatus: 200,
  1226  			ResponseBody:   "{}",
  1227  			WithRequest:    2,
  1228  			WithError:      nil,
  1229  		},
  1230  		{
  1231  			Name:           "404",
  1232  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "series/2?addImportListExclusion=false&deleteFiles=true"),
  1233  			ExpectedMethod: "DELETE",
  1234  			ResponseStatus: 404,
  1235  			ResponseBody:   starrtest.BodyNotFound,
  1236  			WithRequest:    2,
  1237  			WithError:      &starr.ReqError{Code: http.StatusNotFound},
  1238  		},
  1239  	}
  1240  
  1241  	for _, test := range tests {
  1242  		test := test
  1243  		t.Run(test.Name, func(t *testing.T) {
  1244  			t.Parallel()
  1245  			mockServer := test.GetMockServer(t)
  1246  			client := sonarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
  1247  			err := client.DeleteSeriesDefault(test.WithRequest.(int))
  1248  			assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
  1249  		})
  1250  	}
  1251  }
  1252  
  1253  func TestLookupName(t *testing.T) {
  1254  	t.Parallel()
  1255  
  1256  	loc, _ := time.LoadLocation("")
  1257  	date := time.Date(2019, 6, 4, 1, 0, 0, 0, loc)
  1258  
  1259  	tests := []*starrtest.MockData{
  1260  		{
  1261  			Name:           "200",
  1262  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "series/lookup?term=Chernobyl+Breaking+Bad"),
  1263  			ExpectedMethod: "GET",
  1264  			WithRequest:    "Chernobyl Breaking Bad",
  1265  			ResponseStatus: 200,
  1266  			ResponseBody:   listSeries,
  1267  			WithResponse: []*sonarr.Series{
  1268  				{
  1269  					Title:           "Breaking Bad",
  1270  					AlternateTitles: []*sonarr.AlternateTitle{},
  1271  					SortTitle:       "breaking bad",
  1272  					Status:          "ended",
  1273  					Ended:           true,
  1274  					Overview:        "Cool teacher becomes drug dealer",
  1275  					PreviousAiring:  date,
  1276  					Network:         "Netflix",
  1277  					AirTime:         "21:00",
  1278  					Images: []*starr.Image{
  1279  						{
  1280  							CoverType: "banner",
  1281  							URL:       "/MediaCover/1/banner.jpg?lastWrite=637829401993017870",
  1282  							RemoteURL: "https://artworks.thetvdb.com/banners/graphical/81189-g21.jpg",
  1283  						},
  1284  						{
  1285  							CoverType: "poster",
  1286  							URL:       "/MediaCover/1/poster.jpg?lastWrite=637829401994817870",
  1287  							RemoteURL: "https://artworks.thetvdb.com/banners/posters/81189-10.jpg",
  1288  						},
  1289  						{
  1290  							CoverType: "fanart",
  1291  							URL:       "/MediaCover/1/fanart.jpg?lastWrite=637829401996517870",
  1292  							RemoteURL: "https://artworks.thetvdb.com/banners/fanart/original/81189-21.jpg",
  1293  						},
  1294  					},
  1295  					Seasons: []*sonarr.Season{
  1296  						{
  1297  							SeasonNumber: 0,
  1298  							Monitored:    false,
  1299  							Statistics: &sonarr.Statistics{
  1300  								EpisodeFileCount:  0,
  1301  								EpisodeCount:      0,
  1302  								TotalEpisodeCount: 19,
  1303  								SizeOnDisk:        0,
  1304  								PercentOfEpisodes: 0.0,
  1305  							},
  1306  						},
  1307  						{
  1308  							SeasonNumber: 1,
  1309  							Monitored:    true,
  1310  							Statistics: &sonarr.Statistics{
  1311  								PreviousAiring:    date,
  1312  								EpisodeFileCount:  0,
  1313  								EpisodeCount:      7,
  1314  								TotalEpisodeCount: 7,
  1315  								SizeOnDisk:        0,
  1316  								PercentOfEpisodes: 0.0,
  1317  							},
  1318  						},
  1319  						{
  1320  							SeasonNumber: 2,
  1321  							Monitored:    true,
  1322  							Statistics: &sonarr.Statistics{
  1323  								PreviousAiring:    date,
  1324  								EpisodeFileCount:  0,
  1325  								EpisodeCount:      13,
  1326  								TotalEpisodeCount: 13,
  1327  								SizeOnDisk:        0,
  1328  								PercentOfEpisodes: 0.0,
  1329  							},
  1330  						},
  1331  						{
  1332  							SeasonNumber: 3,
  1333  							Monitored:    true,
  1334  							Statistics: &sonarr.Statistics{
  1335  								PreviousAiring:    date,
  1336  								EpisodeFileCount:  0,
  1337  								EpisodeCount:      13,
  1338  								TotalEpisodeCount: 13,
  1339  								SizeOnDisk:        0,
  1340  								PercentOfEpisodes: 0.0,
  1341  							},
  1342  						},
  1343  						{
  1344  							SeasonNumber: 4,
  1345  							Monitored:    true,
  1346  							Statistics: &sonarr.Statistics{
  1347  								PreviousAiring:    date,
  1348  								EpisodeFileCount:  0,
  1349  								EpisodeCount:      13,
  1350  								TotalEpisodeCount: 13,
  1351  								SizeOnDisk:        0,
  1352  								PercentOfEpisodes: 0.0,
  1353  							},
  1354  						},
  1355  						{
  1356  							SeasonNumber: 5,
  1357  							Monitored:    true,
  1358  							Statistics: &sonarr.Statistics{
  1359  								PreviousAiring:    date,
  1360  								EpisodeFileCount:  0,
  1361  								EpisodeCount:      16,
  1362  								TotalEpisodeCount: 16,
  1363  								SizeOnDisk:        0,
  1364  								PercentOfEpisodes: 0.0,
  1365  							},
  1366  						},
  1367  					},
  1368  					Year:              2008,
  1369  					Path:              "/series/Breaking Bad",
  1370  					QualityProfileID:  1,
  1371  					LanguageProfileID: 1,
  1372  					SeasonFolder:      true,
  1373  					Monitored:         true,
  1374  					UseSceneNumbering: false,
  1375  					Runtime:           47,
  1376  					TvdbID:            81189,
  1377  					TvRageID:          18164,
  1378  					TvMazeID:          169,
  1379  					FirstAired:        date,
  1380  					SeriesType:        "standard",
  1381  					CleanTitle:        "breakingbad",
  1382  					ImdbID:            "tt0903747",
  1383  					TitleSlug:         "breaking-bad",
  1384  					RootFolderPath:    "/series/",
  1385  					Certification:     "TV-MA",
  1386  					Genres: []string{
  1387  						"Crime",
  1388  						"Drama",
  1389  						"Suspense",
  1390  						"Thriller",
  1391  					},
  1392  					Tags: []int{
  1393  						11,
  1394  					},
  1395  					Added: date,
  1396  					Ratings: &starr.Ratings{
  1397  						Votes: 31714,
  1398  						Value: 9.4,
  1399  					},
  1400  					Statistics: &sonarr.Statistics{
  1401  						SeasonCount:       5,
  1402  						EpisodeFileCount:  0,
  1403  						EpisodeCount:      62,
  1404  						TotalEpisodeCount: 81,
  1405  						SizeOnDisk:        0,
  1406  						PercentOfEpisodes: 0.0,
  1407  					},
  1408  					ID: 1,
  1409  				},
  1410  				{
  1411  					Title:           "Chernobyl",
  1412  					AlternateTitles: []*sonarr.AlternateTitle{},
  1413  					SortTitle:       "chernobyl",
  1414  					Status:          "ended",
  1415  					Ended:           true,
  1416  					Overview:        "A lot of energy wasted",
  1417  					PreviousAiring:  date,
  1418  					Network:         "HBO",
  1419  					AirTime:         "21:00",
  1420  					Images: []*starr.Image{
  1421  						{
  1422  							CoverType: "banner",
  1423  							URL:       "/MediaCover/2/banner.jpg?lastWrite=637829402715717870",
  1424  							RemoteURL: "https://artworks.thetvdb.com/banners/graphical/5cc9f74c2ddd3.jpg",
  1425  						},
  1426  						{
  1427  							CoverType: "poster",
  1428  							URL:       "/MediaCover/2/poster.jpg?lastWrite=637829402718117870",
  1429  							RemoteURL: "https://artworks.thetvdb.com/banners/posters/5cc12861c93e4.jpg",
  1430  						},
  1431  						{
  1432  							CoverType: "fanart",
  1433  							URL:       "/MediaCover/2/fanart.jpg?lastWrite=637829402721317870",
  1434  							RemoteURL: "https://artworks.thetvdb.com/banners/series/360893/backgrounds/62017319.jpg",
  1435  						},
  1436  					},
  1437  					Seasons: []*sonarr.Season{
  1438  						{
  1439  							SeasonNumber: 0,
  1440  							Monitored:    false,
  1441  							Statistics: &sonarr.Statistics{
  1442  								EpisodeFileCount:  0,
  1443  								EpisodeCount:      0,
  1444  								TotalEpisodeCount: 14,
  1445  								SizeOnDisk:        0,
  1446  								PercentOfEpisodes: 0.0,
  1447  							},
  1448  						},
  1449  						{
  1450  							SeasonNumber: 1,
  1451  							Monitored:    true,
  1452  							Statistics: &sonarr.Statistics{
  1453  								PreviousAiring:    date,
  1454  								EpisodeFileCount:  0,
  1455  								EpisodeCount:      5,
  1456  								TotalEpisodeCount: 5,
  1457  								SizeOnDisk:        0,
  1458  								PercentOfEpisodes: 0.0,
  1459  							},
  1460  						},
  1461  					},
  1462  					Year:              2019,
  1463  					Path:              "/series/Chernobyl",
  1464  					QualityProfileID:  1,
  1465  					LanguageProfileID: 1,
  1466  					SeasonFolder:      true,
  1467  					Monitored:         true,
  1468  					UseSceneNumbering: false,
  1469  					Runtime:           65,
  1470  					TvdbID:            360893,
  1471  					TvRageID:          0,
  1472  					TvMazeID:          30770,
  1473  					FirstAired:        date,
  1474  					SeriesType:        "standard",
  1475  					CleanTitle:        "chernobyl",
  1476  					ImdbID:            "tt7366338",
  1477  					TitleSlug:         "chernobyl",
  1478  					RootFolderPath:    "/series/",
  1479  					Certification:     "TV-MA",
  1480  					Genres: []string{
  1481  						"Drama",
  1482  						"History",
  1483  						"Mini-Series",
  1484  						"Thriller",
  1485  					},
  1486  					Tags: []int{
  1487  						11,
  1488  					},
  1489  					Added: date,
  1490  					Ratings: &starr.Ratings{
  1491  						Votes: 83,
  1492  						Value: 8.7,
  1493  					},
  1494  					Statistics: &sonarr.Statistics{
  1495  						SeasonCount:       1,
  1496  						EpisodeFileCount:  0,
  1497  						EpisodeCount:      5,
  1498  						TotalEpisodeCount: 19,
  1499  						SizeOnDisk:        0,
  1500  						PercentOfEpisodes: 0.0,
  1501  					},
  1502  					ID: 2,
  1503  				},
  1504  			},
  1505  			WithError: nil,
  1506  		},
  1507  		{
  1508  			Name:           "404",
  1509  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "series/lookup?term=Chernobyl+Breaking+Bad"),
  1510  			ExpectedMethod: "GET",
  1511  			WithRequest:    "Chernobyl Breaking Bad",
  1512  			ResponseStatus: 404,
  1513  			ResponseBody:   starrtest.BodyNotFound,
  1514  			WithError:      &starr.ReqError{Code: http.StatusNotFound},
  1515  			WithResponse:   []*sonarr.Series(nil),
  1516  		},
  1517  	}
  1518  
  1519  	for _, test := range tests {
  1520  		test := test
  1521  		t.Run(test.Name, func(t *testing.T) {
  1522  			t.Parallel()
  1523  			mockServer := test.GetMockServer(t)
  1524  			client := sonarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
  1525  			output, err := client.Lookup(test.WithRequest.(string))
  1526  			assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
  1527  			assert.EqualValues(t, output, test.WithResponse, "response is not the same as expected")
  1528  		})
  1529  	}
  1530  }
  1531  
  1532  func TestLookupID(t *testing.T) {
  1533  	t.Parallel()
  1534  
  1535  	loc, _ := time.LoadLocation("")
  1536  	date := time.Date(2019, 6, 4, 1, 0, 0, 0, loc)
  1537  
  1538  	tests := []*starrtest.MockData{
  1539  		{
  1540  			Name:           "200",
  1541  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "series/lookup?term=tvdbid%3A360893"),
  1542  			ExpectedMethod: "GET",
  1543  			WithRequest:    360893,
  1544  			ResponseStatus: 200,
  1545  			ResponseBody:   "[" + secondSeries + "]",
  1546  			WithResponse: []*sonarr.Series{
  1547  				{
  1548  					Title:           "Chernobyl",
  1549  					AlternateTitles: []*sonarr.AlternateTitle{},
  1550  					SortTitle:       "chernobyl",
  1551  					Status:          "ended",
  1552  					Ended:           true,
  1553  					Overview:        "A lot of energy wasted",
  1554  					PreviousAiring:  date,
  1555  					Network:         "HBO",
  1556  					AirTime:         "21:00",
  1557  					Images: []*starr.Image{
  1558  						{
  1559  							CoverType: "banner",
  1560  							URL:       "/MediaCover/2/banner.jpg?lastWrite=637829402715717870",
  1561  							RemoteURL: "https://artworks.thetvdb.com/banners/graphical/5cc9f74c2ddd3.jpg",
  1562  						},
  1563  						{
  1564  							CoverType: "poster",
  1565  							URL:       "/MediaCover/2/poster.jpg?lastWrite=637829402718117870",
  1566  							RemoteURL: "https://artworks.thetvdb.com/banners/posters/5cc12861c93e4.jpg",
  1567  						},
  1568  						{
  1569  							CoverType: "fanart",
  1570  							URL:       "/MediaCover/2/fanart.jpg?lastWrite=637829402721317870",
  1571  							RemoteURL: "https://artworks.thetvdb.com/banners/series/360893/backgrounds/62017319.jpg",
  1572  						},
  1573  					},
  1574  					Seasons: []*sonarr.Season{
  1575  						{
  1576  							SeasonNumber: 0,
  1577  							Monitored:    false,
  1578  							Statistics: &sonarr.Statistics{
  1579  								EpisodeFileCount:  0,
  1580  								EpisodeCount:      0,
  1581  								TotalEpisodeCount: 14,
  1582  								SizeOnDisk:        0,
  1583  								PercentOfEpisodes: 0.0,
  1584  							},
  1585  						},
  1586  						{
  1587  							SeasonNumber: 1,
  1588  							Monitored:    true,
  1589  							Statistics: &sonarr.Statistics{
  1590  								PreviousAiring:    date,
  1591  								EpisodeFileCount:  0,
  1592  								EpisodeCount:      5,
  1593  								TotalEpisodeCount: 5,
  1594  								SizeOnDisk:        0,
  1595  								PercentOfEpisodes: 0.0,
  1596  							},
  1597  						},
  1598  					},
  1599  					Year:              2019,
  1600  					Path:              "/series/Chernobyl",
  1601  					QualityProfileID:  1,
  1602  					LanguageProfileID: 1,
  1603  					SeasonFolder:      true,
  1604  					Monitored:         true,
  1605  					UseSceneNumbering: false,
  1606  					Runtime:           65,
  1607  					TvdbID:            360893,
  1608  					TvRageID:          0,
  1609  					TvMazeID:          30770,
  1610  					FirstAired:        date,
  1611  					SeriesType:        "standard",
  1612  					CleanTitle:        "chernobyl",
  1613  					ImdbID:            "tt7366338",
  1614  					TitleSlug:         "chernobyl",
  1615  					RootFolderPath:    "/series/",
  1616  					Certification:     "TV-MA",
  1617  					Genres: []string{
  1618  						"Drama",
  1619  						"History",
  1620  						"Mini-Series",
  1621  						"Thriller",
  1622  					},
  1623  					Tags: []int{
  1624  						11,
  1625  					},
  1626  					Added: date,
  1627  					Ratings: &starr.Ratings{
  1628  						Votes: 83,
  1629  						Value: 8.7,
  1630  					},
  1631  					Statistics: &sonarr.Statistics{
  1632  						SeasonCount:       1,
  1633  						EpisodeFileCount:  0,
  1634  						EpisodeCount:      5,
  1635  						TotalEpisodeCount: 19,
  1636  						SizeOnDisk:        0,
  1637  						PercentOfEpisodes: 0.0,
  1638  					},
  1639  					ID: 2,
  1640  				},
  1641  			},
  1642  			WithError: nil,
  1643  		},
  1644  		{
  1645  			Name:           "404",
  1646  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "series/lookup?term=tvdbid%3A360893"),
  1647  			ExpectedMethod: "GET",
  1648  			WithRequest:    360893,
  1649  			ResponseStatus: 404,
  1650  			ResponseBody:   starrtest.BodyNotFound,
  1651  			WithError:      &starr.ReqError{Code: http.StatusNotFound},
  1652  			WithResponse:   []*sonarr.Series(nil),
  1653  		},
  1654  	}
  1655  
  1656  	for _, test := range tests {
  1657  		test := test
  1658  		t.Run(test.Name, func(t *testing.T) {
  1659  			t.Parallel()
  1660  			mockServer := test.GetMockServer(t)
  1661  			client := sonarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
  1662  			output, err := client.GetSeriesLookup("", int64(test.WithRequest.(int)))
  1663  			assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
  1664  			assert.EqualValues(t, output, test.WithResponse, "response is not the same as expected")
  1665  		})
  1666  	}
  1667  }