golift.io/starr@v1.0.0/sonarr/episode_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  	episode = `{
    17  		"seriesId": 53,
    18  		"tvdbId": 8444132,
    19  		"episodeFileId": 3260,
    20  		"seasonNumber": 1,
    21  		"episodeNumber": 1,
    22  		"title": "When You're Lost in the Darkness",
    23  		"airDate": "2023-01-15",
    24  		"airDateUtc": "2023-01-16T02:00:00Z",
    25  		"overview": "Twenty years after a fungal outbreak ravages the planet, survivors Joel and Tess are tasked with a mission that could change everything.",
    26  		"episodeFile": {
    27  			"seriesId": 53,
    28  			"seasonNumber": 1,
    29  			"relativePath": "Season 01/The Last of Us (2023) - S01E01 - When You're Lost in the Darkness [AMZN WEBDL-1080p Proper][EAC3 Atmos 5.1][h264]-FLUX.mkv",
    30  			"path": "/media/tv/The Last of Us (2023) [imdb-tt3581920] [tvdbid-392256]/Season 01/The Last of Us (2023) - S01E01 - When You're Lost in the Darkness [AMZN WEBDL-1080p Proper][EAC3 Atmos 5.1][h264]-FLUX.mkv",
    31  			"size": 6002269811,
    32  			"dateAdded": "2023-03-14T03:34:28Z",
    33  			"sceneName": "The.Last.Of.Us.S01E01.When.Your.Lost.in.the.Darkness.REPACK.1080p.AMZN.WEB-DL.DDP5.1.Atmos.H.264-FLUX",
    34  			"releaseGroup": "FLUX",
    35  			"languages": [
    36  				{
    37  					"id": 1,
    38  					"name": "English"
    39  				}
    40  			],
    41  			"quality": {
    42  				"quality": {
    43  					"id": 3,
    44  					"name": "WEBDL-1080p",
    45  					"source": "web",
    46  					"resolution": 1080
    47  				},
    48  				"revision": {
    49  					"version": 2,
    50  					"real": 0,
    51  					"isRepack": true
    52  				}
    53  			},
    54  			"customFormats": [
    55  				{
    56  					"id": 26,
    57  					"name": "AMZN"
    58  				},
    59  				{
    60  					"id": 46,
    61  					"name": "WEB Tier 01"
    62  				},
    63  				{
    64  					"id": 49,
    65  					"name": "Repack/Proper"
    66  				}
    67  			],
    68  			"mediaInfo": {
    69  				"audioBitrate": 768000,
    70  				"audioChannels": 5.1,
    71  				"audioCodec": "EAC3 Atmos",
    72  				"audioLanguages": "eng",
    73  				"audioStreamCount": 1,
    74  				"videoBitDepth": 8,
    75  				"videoBitrate": 0,
    76  				"videoCodec": "h264",
    77  				"videoFps": 23.976,
    78  				"videoDynamicRange": "",
    79  				"videoDynamicRangeType": "",
    80  				"resolution": "1920x1080",
    81  				"runTime": "1:20:56",
    82  				"scanType": "Progressive",
    83  				"subtitles": "eng/eng/spa/spa"
    84  			},
    85  			"qualityCutoffNotMet": false,
    86  			"id": 3260
    87  		},
    88  		"hasFile": true,
    89  		"monitored": true,
    90  		"unverifiedSceneNumbering": false,
    91  		"series": {
    92  			"title": "The Last of Us",
    93  			"sortTitle": "last of us",
    94  			"status": "continuing",
    95  			"ended": false,
    96  			"overview": "After a global pandemic destroys civilization, a hardened survivor takes charge of a 14-year-old girl who may be humanity’s last hope.",
    97  			"network": "HBO",
    98  			"airTime": "21:00",
    99  			"images": [
   100  				{
   101  					"coverType": "banner",
   102  					"remoteUrl": "https://artworks.thetvdb.com/banners/v4/series/392256/banners/63cded40a22f4.jpg"
   103  				},
   104  				{
   105  					"coverType": "poster",
   106  					"remoteUrl": "https://artworks.thetvdb.com/banners/v4/series/392256/posters/6362e8b41ca10.jpg"
   107  				},
   108  				{
   109  					"coverType": "fanart",
   110  					"remoteUrl": "https://artworks.thetvdb.com/banners/v4/series/392256/backgrounds/637e513564daf.jpg"
   111  				},
   112  				{
   113  					"coverType": "unknown",
   114  					"remoteUrl": "https://artworks.thetvdb.com/banners/v4/series/392256/clearlogo/636712bfd63b2.png"
   115  				}
   116  			],
   117  			"originalLanguage": {
   118  				"id": 1,
   119  				"name": "English"
   120  			},
   121  			"seasons": [
   122  				{
   123  					"seasonNumber": 0,
   124  					"monitored": false
   125  				},
   126  				{
   127  					"seasonNumber": 1,
   128  					"monitored": true
   129  				}
   130  			],
   131  			"year": 2023,
   132  			"path": "/media/tv/The Last of Us (2023) [imdb-tt3581920] [tvdbid-392256]",
   133  			"qualityProfileId": 7,
   134  			"seasonFolder": true,
   135  			"monitored": true,
   136  			"useSceneNumbering": false,
   137  			"runtime": 58,
   138  			"tvdbId": 392256,
   139  			"tvRageId": 0,
   140  			"tvMazeId": 46562,
   141  			"firstAired": "2023-01-15T00:00:00Z",
   142  			"seriesType": "standard",
   143  			"cleanTitle": "thelastus",
   144  			"imdbId": "tt3581920",
   145  			"titleSlug": "the-last-of-us",
   146  			"certification": "TV-MA",
   147  			"genres": [
   148  				"Action",
   149  				"Adventure",
   150  				"Drama",
   151  				"Horror",
   152  				"Science Fiction"
   153  			],
   154  			"tags": [],
   155  			"added": "2023-01-17T21:14:56Z",
   156  			"ratings": {
   157  				"votes": 0,
   158  				"value": 0
   159  			},
   160  			"languageProfileId": 1,
   161  			"id": 53
   162  		},
   163  		"images": [
   164  			{
   165  				"coverType": "screenshot",
   166  				"remoteUrl": "https://artworks.thetvdb.com/banners/v4/episode/8444132/screencap/638bf7ef8ed12.jpg"
   167  			}
   168  		],
   169  		"grabbed": false,
   170  		"id": 4186
   171  	}`
   172  )
   173  
   174  func TestGetEpisodeByID(t *testing.T) {
   175  	t.Parallel()
   176  
   177  	loc, _ := time.LoadLocation("")
   178  	airDate := time.Date(2023, 1, 16, 2, 0, 0, 0, loc)
   179  	addedDate := time.Date(2023, 1, 17, 21, 14, 56, 0, loc)
   180  	firstAiredDate := time.Date(2023, 1, 15, 0, 0, 0, 0, loc)
   181  
   182  	tests := []*starrtest.MockData{
   183  		{
   184  			Name:           "200",
   185  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "episode", "4186"),
   186  			ExpectedMethod: "GET",
   187  			ResponseStatus: 200,
   188  			ResponseBody:   episode,
   189  			WithRequest:    4186,
   190  			WithResponse: &sonarr.Episode{
   191  				ID:            4186,
   192  				SeriesID:      53,
   193  				TvdbID:        8444132,
   194  				EpisodeFileID: 3260,
   195  				SeasonNumber:  1,
   196  				EpisodeNumber: 1,
   197  				AirDate:       "2023-01-15",
   198  				AirDateUtc:    airDate,
   199  				Title:         "When You're Lost in the Darkness",
   200  				Overview:      "Twenty years after a fungal outbreak ravages the planet, survivors Joel and Tess are tasked with a mission that could change everything.",
   201  				HasFile:       true,
   202  				Monitored:     true,
   203  				Images: []*starr.Image{
   204  					{
   205  						CoverType: "screenshot",
   206  						RemoteURL: "https://artworks.thetvdb.com/banners/v4/episode/8444132/screencap/638bf7ef8ed12.jpg",
   207  					},
   208  				},
   209  				Series: &sonarr.Series{
   210  					ID:                53,
   211  					Ended:             false,
   212  					Monitored:         true,
   213  					SeasonFolder:      true,
   214  					Runtime:           58,
   215  					Year:              2023,
   216  					LanguageProfileID: 1,
   217  					QualityProfileID:  7,
   218  					TvdbID:            392256,
   219  					TvMazeID:          46562,
   220  					TvRageID:          0,
   221  					AirTime:           "21:00",
   222  					Certification:     "TV-MA",
   223  					CleanTitle:        "thelastus",
   224  					ImdbID:            "tt3581920",
   225  					Network:           "HBO",
   226  					Overview:          "After a global pandemic destroys civilization, a hardened survivor takes charge of a 14-year-old girl who may be humanity’s last hope.",
   227  					Path:              "/media/tv/The Last of Us (2023) [imdb-tt3581920] [tvdbid-392256]",
   228  					SeriesType:        "standard",
   229  					SortTitle:         "last of us",
   230  					Status:            "continuing",
   231  					Title:             "The Last of Us",
   232  					TitleSlug:         "the-last-of-us",
   233  					Added:             addedDate,
   234  					FirstAired:        firstAiredDate,
   235  					Ratings:           &starr.Ratings{},
   236  					Tags:              []int{},
   237  					Genres: []string{
   238  						"Action",
   239  						"Adventure",
   240  						"Drama",
   241  						"Horror",
   242  						"Science Fiction",
   243  					},
   244  					Seasons: []*sonarr.Season{
   245  						{
   246  							SeasonNumber: 0,
   247  							Monitored:    false,
   248  						},
   249  						{
   250  							SeasonNumber: 1,
   251  							Monitored:    true,
   252  						},
   253  					},
   254  					Images: []*starr.Image{
   255  						{
   256  							CoverType: "banner",
   257  							RemoteURL: "https://artworks.thetvdb.com/banners/v4/series/392256/banners/63cded40a22f4.jpg",
   258  						},
   259  						{
   260  							CoverType: "poster",
   261  							RemoteURL: "https://artworks.thetvdb.com/banners/v4/series/392256/posters/6362e8b41ca10.jpg",
   262  						},
   263  						{
   264  							CoverType: "fanart",
   265  							RemoteURL: "https://artworks.thetvdb.com/banners/v4/series/392256/backgrounds/637e513564daf.jpg",
   266  						},
   267  						{
   268  							CoverType: "unknown",
   269  							RemoteURL: "https://artworks.thetvdb.com/banners/v4/series/392256/clearlogo/636712bfd63b2.png",
   270  						},
   271  					},
   272  				},
   273  			},
   274  			WithError: nil,
   275  		},
   276  		{
   277  			Name:           "404",
   278  			ExpectedPath:   path.Join("/", starr.API, sonarr.APIver, "episode", "4186"),
   279  			ExpectedMethod: "GET",
   280  			ResponseStatus: 404,
   281  			ResponseBody:   starrtest.BodyNotFound,
   282  			WithRequest:    4186,
   283  			WithError:      &starr.ReqError{Code: http.StatusNotFound},
   284  			WithResponse:   (*sonarr.Episode)(nil),
   285  		},
   286  	}
   287  
   288  	for _, test := range tests {
   289  		test := test
   290  		t.Run(test.Name, func(t *testing.T) {
   291  			t.Parallel()
   292  			mockServer := test.GetMockServer(t)
   293  			client := sonarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
   294  			output, err := client.GetEpisodeByID(int64(test.WithRequest.(int)))
   295  			assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
   296  			assert.EqualValues(t, output, test.WithResponse, "response is not the same as expected")
   297  		})
   298  	}
   299  }