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

     1  package radarr_test
     2  
     3  import (
     4  	"net/http"
     5  	"path"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  	"golift.io/starr"
    10  	"golift.io/starr/radarr"
    11  	"golift.io/starr/starrtest"
    12  )
    13  
    14  func TestEditMovies(t *testing.T) {
    15  	t.Parallel()
    16  
    17  	tests := []*starrtest.MockData{
    18  		{
    19  			Name:           "200",
    20  			ExpectedPath:   path.Join("/", starr.API, radarr.APIver, "movie", "editor"),
    21  			ResponseStatus: http.StatusOK,
    22  			ResponseBody:   `[{"id": 7, "monitored": true},{"id": 3, "monitored": true}]`,
    23  			WithError:      nil,
    24  			WithRequest: &radarr.BulkEdit{
    25  				MovieIDs:    []int64{7, 3},
    26  				Monitored:   starr.True(),
    27  				DeleteFiles: starr.False(),
    28  			},
    29  			ExpectedRequest: `{"movieIds":[7,3],"monitored":true,"deleteFiles":false}` + "\n",
    30  			ExpectedMethod:  http.MethodPut,
    31  			WithResponse:    []*radarr.Movie{{ID: 7, Monitored: true}, {ID: 3, Monitored: true}},
    32  		},
    33  		{
    34  			Name:           "200",
    35  			ExpectedPath:   path.Join("/", starr.API, radarr.APIver, "movie", "editor"),
    36  			ResponseStatus: http.StatusOK,
    37  			ResponseBody: `[{"id":17,"minimumAvailability":"tba","tags":[44,55,66]},` +
    38  				`{"id":13,"minimumAvailability":"tba","tags":[44,55,66]}]`,
    39  			WithError: nil,
    40  			WithRequest: &radarr.BulkEdit{
    41  				MovieIDs:            []int64{17, 13},
    42  				Tags:                []int{44, 55, 66},
    43  				ApplyTags:           starr.TagsAdd.Ptr(),
    44  				MinimumAvailability: radarr.AvailabilityToBeAnnounced.Ptr(),
    45  			},
    46  			ExpectedRequest: `{"movieIds":[17,13],"minimumAvailability":"tba","tags":[44,55,66],"applyTags":"add"}` + "\n",
    47  			ExpectedMethod:  http.MethodPut,
    48  			WithResponse: []*radarr.Movie{
    49  				{ID: 17, MinimumAvailability: radarr.AvailabilityToBeAnnounced, Tags: []int{44, 55, 66}},
    50  				{ID: 13, MinimumAvailability: radarr.AvailabilityToBeAnnounced, Tags: []int{44, 55, 66}},
    51  			},
    52  		},
    53  	}
    54  
    55  	for _, test := range tests {
    56  		test := test
    57  		t.Run(test.Name, func(t *testing.T) {
    58  			t.Parallel()
    59  			mockServer := test.GetMockServer(t)
    60  			client := radarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
    61  			output, err := client.EditMovies(test.WithRequest.(*radarr.BulkEdit))
    62  			assert.ErrorIs(t, err, test.WithError, "the wrong error was returned")
    63  			assert.EqualValues(t, test.WithResponse, output, "make sure ResponseBody and WithResponse are a match")
    64  		})
    65  	}
    66  }
    67  
    68  func TestDeleteMovies(t *testing.T) {
    69  	t.Parallel()
    70  
    71  	tests := []*starrtest.MockData{
    72  		{
    73  			Name:           "200",
    74  			ExpectedPath:   path.Join("/", starr.API, radarr.APIver, "movie", "editor"),
    75  			ResponseStatus: http.StatusOK,
    76  			WithError:      nil,
    77  			WithRequest: &radarr.BulkEdit{
    78  				MovieIDs:    []int64{7, 3},
    79  				Monitored:   starr.False(),
    80  				DeleteFiles: starr.True(),
    81  			},
    82  			ExpectedRequest: `{"movieIds":[7,3],"monitored":false,"deleteFiles":true}` + "\n",
    83  			ExpectedMethod:  http.MethodDelete,
    84  		},
    85  	}
    86  
    87  	for _, test := range tests {
    88  		test := test
    89  		t.Run(test.Name, func(t *testing.T) {
    90  			t.Parallel()
    91  			mockServer := test.GetMockServer(t)
    92  			client := radarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
    93  			err := client.DeleteMovies(test.WithRequest.(*radarr.BulkEdit))
    94  			assert.ErrorIs(t, err, test.WithError, "the wrong error was returned")
    95  		})
    96  	}
    97  }