package handlers_test

import (
	"fmt"
	"net/http"
	"testing"

	"otaupdate/handlers"
	"otaupdate/services"

	mo "github.com/fiskerinc/cloud-services/pkg/db/queries/mocks"
	th "github.com/fiskerinc/cloud-services/pkg/testhelper"
)

func TestGetVehicleYears(t *testing.T) {
	mock := mo.MockCars{}
	services.GetDB().SetCars(&mock)
	tests := []mo.DBHttpTest{
		{
			Name:             "Call",
			Request:          th.MakeTestRequest(http.MethodGet, "http://example.com/vehicleyears", nil),
			ExpectedStatus:   http.StatusOK,
			ExpectedResponse: `{"data":[3000]}`,
		},
		{
			Name:             "Error",
			Request:          th.MakeTestRequest(http.MethodGet, "http://example.com/vehicleyears", nil),
			ExpectedStatus:   http.StatusServiceUnavailable,
			ExpectedResponse: `{"message":"something went wrong","error":"Service Unavailable"}`,
			DBTestCase: mo.DBTestCase{
				MockError: fmt.Errorf("something went wrong"),
			},
		},
	}

	mo.RunDBTests(t, tests, handlers.HandleVehicleYears, &mock)
}
