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 TestGetVehicleModels(t *testing.T) {
	mock := mo.MockCars{}
	services.GetDB().SetCars(&mock)
	tests := []mo.DBHttpTest{
		{
			Name:             "Call",
			Request:          th.MakeTestRequest(http.MethodGet, "http://example.com/vehiclemodels", nil),
			ExpectedStatus:   http.StatusOK,
			ExpectedResponse: `{"data":["1G1FP87S3GN100062"]}`,
		},
		{
			Name:             "Error",
			Request:          th.MakeTestRequest(http.MethodGet, "http://example.com/vehiclemodels", 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.HandleVehicleModels, &mock)
}
