package handlers_test

import (
	"net/http"
	"otaupdate/handlers"
	"otaupdate/services"
	"testing"

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

func TestUpdateManifestECUAdd(t *testing.T) {
	mock := mo.MockUpdateManifests{}
	services.GetDB().SetUpdateManifests(&mock)

	tests := []mo.DBHttpTest{
		{
			Name: "Valid data",
			Request: th.MakeTestRequest(http.MethodPost, "http://example.com/manifest", common.UpdateManifestECU{
				UpdateManifestID:  1,
				ECU:               "ADAS",
				Version:           "2112",
				ConfigurationMask: "9999999",
				Mode:              "D",
			}),
			ExpectedStatus:   http.StatusOK,
			ExpectedResponse: `{"id":1,"manifest_id":1,"name":"ADAS","version":"2112","configuration_mask":"9999999","mode":"D"}`,
		},
		{
			Name:             "No data",
			Request:          th.MakeTestRequest(http.MethodPost, "http://example.com/manifest", nil),
			ExpectedStatus:   http.StatusBadRequest,
			ExpectedResponse: `{"message":"UpdateManifestID required. ECU required. Version required. Mode required","error":"Bad Request"}`,
		},
	}

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