50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package api
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"testing"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestCanonicalSonarrSeriesStatus(t *testing.T) {
|
||
|
|
cases := map[string]string{
|
||
|
|
" continuing ": "Continuing",
|
||
|
|
"ended": "Ended",
|
||
|
|
"cancelled": "Cancelled",
|
||
|
|
"canceled": "Cancelled",
|
||
|
|
"upcoming": "Upcoming",
|
||
|
|
"deleted": "",
|
||
|
|
"unknown": "",
|
||
|
|
}
|
||
|
|
for input, want := range cases {
|
||
|
|
if got := canonicalSonarrSeriesStatus(input); got != want {
|
||
|
|
t.Errorf("canonicalSonarrSeriesStatus(%q) = %q, want %q", input, got, want)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestInjectSeriesStatusReplacesEmbyWithoutDroppingFields(t *testing.T) {
|
||
|
|
raw := json.RawMessage(`{"Id":"series-1","Status":"Continuing","FutureField":true}`)
|
||
|
|
decorated := injectSeriesStatus(raw, "Ended")
|
||
|
|
var item struct {
|
||
|
|
Status string `json:"Status"`
|
||
|
|
FutureField bool `json:"FutureField"`
|
||
|
|
}
|
||
|
|
if err := json.Unmarshal(decorated, &item); err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
if item.Status != "Ended" || !item.FutureField {
|
||
|
|
t.Fatalf("decorated item = %+v", item)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestSeriesTVDBIDOnlyAcceptsSeries(t *testing.T) {
|
||
|
|
series := json.RawMessage(`{"Type":"Series","ProviderIds":{"Tvdb":"1234"}}`)
|
||
|
|
if got := seriesTVDBID(series); got != 1234 {
|
||
|
|
t.Fatalf("series TVDB id = %d, want 1234", got)
|
||
|
|
}
|
||
|
|
movie := json.RawMessage(`{"Type":"Movie","ProviderIds":{"Tvdb":"1234"}}`)
|
||
|
|
if got := seriesTVDBID(movie); got != 0 {
|
||
|
|
t.Fatalf("movie TVDB id = %d, want 0", got)
|
||
|
|
}
|
||
|
|
}
|