package handlers_test

import (
	"net/http"
	"testing"

	"otaupdate/handlers"
	"otaupdate/services"

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

func TestCarUpdateDelete(t *testing.T) {
	services.GetDB().SetCarUpdates(&mocks.MockCarUpdates{})
	tests := []th.BasicHttpTest{
		{
			Name:             "No id",
			Request:          th.MakeTestRequest(http.MethodGet, "http://example.com/carupdates", nil),
			ExpectedStatus:   http.StatusBadRequest,
			ExpectedResponse: `{"message":"id required","error":"Bad Request"}`,
		},
		{
			Name:             "Zero id",
			Request:          th.MakeTestRequest(http.MethodGet, "http://example.com/carupdates?id=0", nil),
			ExpectedStatus:   http.StatusBadRequest,
			ExpectedResponse: `{"message":"id required","error":"Bad Request"}`,
		},
		{
			Name:             "Good id",
			Request:          th.MakeTestRequest(http.MethodGet, "http://example.com/carupdates?id=1", nil),
			ExpectedStatus:   http.StatusOK,
			ExpectedResponse: `{"message":"Deleted"}`,
		},
	}

	th.RunBasicHttpTests(t, tests, handlers.HandleCarUpdateDelete)
}
