golift.io/starr@v1.0.0/radarr/calendar_test.go (about)

     1  package radarr_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/radarr"
    11  	"golift.io/starr/starrtest"
    12  )
    13  
    14  var testMovieJSON = `{
    15  	  "title": "Beast",
    16  	  "originalTitle": "Beast",
    17  	  "originalLanguage": {
    18  		"id": 1,
    19  		"name": "English"
    20  	  },
    21  	  "alternateTitles": [
    22  		{
    23  		  "sourceType": "tmdb",
    24  		  "movieMetadataId": 2671,
    25  		  "title": "Zvērs",
    26  		  "sourceId": 0,
    27  		  "votes": 0,
    28  		  "voteCount": 0,
    29  		  "language": {
    30  			"id": 1,
    31  			"name": "English"
    32  		  },
    33  		  "id": 18219
    34  		}
    35  	  ],
    36  	  "secondaryYearSourceId": 0,
    37  	  "sortTitle": "beast",
    38  	  "sizeOnDisk": 1796921629,
    39  	  "status": "released",
    40  	  "overview": "...",
    41  	  "inCinemas": "2022-08-11T00:00:00Z",
    42  	  "physicalRelease": "2022-10-11T00:00:00Z",
    43  	  "digitalRelease": "2022-09-09T00:00:00Z",
    44  	  "images": [
    45  		{
    46  		  "coverType": "fanart",
    47  		  "url": "https://image.tmdb.org/t/p/original/8TUb2U9GN3PonbXAQ1FBcJ4XeXu.jpg"
    48  		}
    49  	  ],
    50  	  "website": "https://www.beastmovie.com",
    51  	  "year": 2022,
    52  	  "hasFile": true,
    53  	  "youTubeTrailerId": "oQMc7Sq36mI",
    54  	  "studio": "Universal Pictures",
    55  	  "path": "/movies/Beast (2022)",
    56  	  "qualityProfileId": 4,
    57  	  "monitored": true,
    58  	  "minimumAvailability": "announced",
    59  	  "isAvailable": true,
    60  	  "folderName": "/movies/Beast (2022)",
    61  	  "runtime": 93,
    62  	  "cleanTitle": "beast",
    63  	  "imdbId": "tt13223398",
    64  	  "tmdbId": 760741,
    65  	  "titleSlug": "760741",
    66  	  "certification": "R",
    67  	  "genres": [
    68  		"Thriller"
    69  	  ],
    70  	  "tags": [],
    71  	  "added": "2022-08-30T08:27:15Z",
    72  	  "ratings": {
    73  		"rottenTomatoes": {
    74  		  "votes": 0,
    75  		  "value": 69,
    76  		  "type": "user"
    77  		}
    78  	  },
    79  	  "movieFile": {},
    80  	  "popularity": 2240.269,
    81  	  "id": 2295
    82  	}`
    83  
    84  // This matches the json above.
    85  var testMovieStruct = radarr.Movie{
    86  	ID:    2295,
    87  	Title: "Beast",
    88  	OriginalLanguage: &starr.Value{
    89  		ID:   1,
    90  		Name: "English",
    91  	},
    92  	AlternateTitles: []*radarr.AlternativeTitle{{
    93  		SourceType:      "tmdb",
    94  		MovieMetadataID: 2671,
    95  		Title:           "Zvērs",
    96  		SourceID:        0,
    97  		Votes:           0,
    98  		VoteCount:       0,
    99  		Language: &starr.Value{
   100  			ID:   1,
   101  			Name: "English",
   102  		},
   103  		ID: 18219,
   104  	}},
   105  	Path:             "/movies/Beast (2022)",
   106  	QualityProfileID: 4,
   107  	TmdbID:           760741,
   108  	OriginalTitle:    "Beast",
   109  	Popularity:       2240.269,
   110  
   111  	SecondaryYearSourceID: 0,
   112  	SortTitle:             "beast",
   113  	SizeOnDisk:            1796921629,
   114  	Status:                "released",
   115  	Overview:              "...",
   116  	InCinemas:             time.Date(2022, 8, 11, 0, 0, 0, 0, time.UTC),
   117  	PhysicalRelease:       time.Date(2022, 10, 11, 0, 0, 0, 0, time.UTC),
   118  	DigitalRelease:        time.Date(2022, 9, 9, 0, 0, 0, 0, time.UTC),
   119  	Images: []*starr.Image{{
   120  		CoverType: "fanart",
   121  		URL:       "https://image.tmdb.org/t/p/original/8TUb2U9GN3PonbXAQ1FBcJ4XeXu.jpg",
   122  	}},
   123  	Website:             "https://www.beastmovie.com",
   124  	Year:                2022,
   125  	HasFile:             true,
   126  	YouTubeTrailerID:    "oQMc7Sq36mI",
   127  	Studio:              "Universal Pictures",
   128  	Monitored:           true,
   129  	MinimumAvailability: radarr.AvailabilityAnnounced,
   130  	IsAvailable:         true,
   131  	FolderName:          "/movies/Beast (2022)",
   132  	Runtime:             93,
   133  	CleanTitle:          "beast",
   134  	ImdbID:              "tt13223398",
   135  	TitleSlug:           "760741",
   136  	Certification:       "R",
   137  	Genres:              []string{"Thriller"},
   138  	Tags:                []int{},
   139  	Added:               time.Date(2022, 8, 30, 8, 27, 15, 0, time.UTC),
   140  	Ratings:             map[string]starr.Ratings{"rottenTomatoes": {Votes: 0, Value: 69, Type: "user"}},
   141  	MovieFile:           &radarr.MovieFile{}, // this could get tested..
   142  }
   143  
   144  func TestGetCalendar(t *testing.T) {
   145  	t.Parallel()
   146  
   147  	tests := []*starrtest.MockData{
   148  		{
   149  			Name: "200",
   150  			ExpectedPath: "/api/v3/calendar" +
   151  				"?end=2020-02-20T04%3A20%3A20.000Z" +
   152  				"&start=2020-02-20T04%3A20%3A20.000Z" +
   153  				"&unmonitored=true",
   154  			ResponseStatus: http.StatusOK,
   155  			ResponseBody:   `[` + testMovieJSON + `]`,
   156  			WithRequest: radarr.Calendar{
   157  				Start:       time.Unix(1582172420, 0),
   158  				End:         time.Unix(1582172420, 0),
   159  				Unmonitored: true,
   160  			},
   161  			WithError:      nil,
   162  			ExpectedMethod: http.MethodGet,
   163  			WithResponse:   []*radarr.Movie{&testMovieStruct},
   164  		},
   165  		{
   166  			Name: "404",
   167  			ExpectedPath: "/api/v3/calendar" +
   168  				"?end=2020-02-20T04%3A20%3A20.000Z" +
   169  				"&start=2020-02-20T04%3A20%3A20.000Z" +
   170  				"&unmonitored=true",
   171  			ResponseStatus: http.StatusNotFound,
   172  			ResponseBody:   `{"message": "NotFound"}`,
   173  			WithError:      &starr.ReqError{Code: http.StatusNotFound},
   174  			ExpectedMethod: http.MethodGet,
   175  			WithRequest: radarr.Calendar{
   176  				Start:       time.Unix(1582172420, 0),
   177  				End:         time.Unix(1582172420, 0),
   178  				Unmonitored: true,
   179  			},
   180  			WithResponse: []*radarr.Movie(nil),
   181  		},
   182  	}
   183  
   184  	for _, test := range tests {
   185  		test := test
   186  		t.Run(test.Name, func(t *testing.T) {
   187  			t.Parallel()
   188  			mockServer := test.GetMockServer(t)
   189  			client := radarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
   190  			output, err := client.GetCalendar(test.WithRequest.(radarr.Calendar))
   191  			assert.ErrorIs(t, err, test.WithError, "the wrong error was returned")
   192  			assert.EqualValues(t, test.WithResponse, output, "make sure ResponseBody and WithResponse are a match")
   193  		})
   194  	}
   195  }
   196  
   197  /**/