func Test_ParseAppendSeriesListRequest_OK(t *testing.T) { data := ` { "Data": { "SeriesID": 2 } }` body := bytes.NewReader([]byte(data)) req, err := http.NewRequest("POST", "/", body) if err != nil { t.Fatal(err) } ginCtx := gin.Context{} ginCtx.Request = req s, err := ParseAppendSeriesListRequest(&ginCtx) if err != nil { t.Fatal(err) } expect := SeriesListRequestData{ SeriesID: 2, } if expect.SeriesID != s.SeriesID { m := fmt.Sprintf("Expect %v was %v", expect, s) t.Fatal(m) } }
func Test_ParseUserRequest_OK(t *testing.T) { data := ` { "Data": { "Name": "name", "Password": "******" } }` body := bytes.NewReader([]byte(data)) req, err := http.NewRequest("POST", "/", body) if err != nil { t.Fatal(err) } ginCtx := gin.Context{} ginCtx.Request = req u, err := ParseNewUserRequest(&ginCtx) expect := User{ Name: "name", Password: "******", } if err := EqualUser(expect, u); err != nil { t.Fatal(err) } }
func Test_ParseSeriesRequest_OK(t *testing.T) { data := ` { "Data": { "Title": "Title", "Image": "Image" } }` body := bytes.NewReader([]byte(data)) req, err := http.NewRequest("POST", "/", body) if err != nil { t.Fatal(err) } ginCtx := gin.Context{} ginCtx.Request = req s, err := ParseNewSeriesRequest(&ginCtx) expect := Series{ Title: "Title", Image: "Image", } if err := EqualSeries(expect, s); err != nil { t.Fatal(err) } }
func Test_ParseUpdateLastWatchedRequest_OK(t *testing.T) { data := ` { "Data": { "UserID": 1, "SeriesID": 2, "Session": 3, "Episode": 4 } }` body := bytes.NewReader([]byte(data)) req, err := http.NewRequest("POST", "/", body) if err != nil { t.Fatal(err) } ginCtx := gin.Context{} ginCtx.Request = req s, err := ParseUpdateLastWatchedRequest(&ginCtx) if err != nil { t.Fatal(err) } expect := LastWatched{ SeriesID: 2, Session: 3, Episode: 4, } if expect.SeriesID != s.SeriesID || expect.Session != s.Session || expect.Episode != s.Episode { m := fmt.Sprintf("Expect %v was %v", expect, s) t.Fatal(m) } }
func Test_ParseNewSeriesRequest_FailMissingFields(t *testing.T) { data := ` { "Data": { "Title": "Title" } }` body := bytes.NewReader([]byte(data)) req, err := http.NewRequest("POST", "/", body) if err != nil { t.Fatal(err) } ginCtx := gin.Context{} ginCtx.Request = req _, err = ParseNewSeriesRequest(&ginCtx) expect := NewMissingFieldError("Image") if err.Error() != expect.Error() { t.Fatal("Expect", expect, "was", err) } }