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 TestUpdateManifestDelete(t *testing.T) {
	services.GetDB().SetUpdateManifests(&mocks.MockUpdateManifests{})

	tests := []th.BasicHttpTest{
		{
			Name:             "No id",
			Request:          th.MakeTestRequest(http.MethodGet, "http://example.com/manifest", nil),
			ExpectedStatus:   http.StatusBadRequest,
			ExpectedResponse: `{"message":"id required","error":"Bad Request"}`,
		},
		{
			Name:             "Zero id",
			Request:          th.MakeTestRequest(http.MethodGet, "http://example.com/manifest?id=0", nil),
			ExpectedStatus:   http.StatusBadRequest,
			ExpectedResponse: `{"message":"id required","error":"Bad Request"}`,
		},
		{
			Name:             "Good id",
			Request:          th.MakeTestRequest(http.MethodGet, "http://example.com/manifest?id=1", nil),
			ExpectedStatus:   http.StatusOK,
			ExpectedResponse: `{"message":"Deleted"}`,
		},
	}

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