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 TestHandleUpdateManifestSUMVersionRxSwinsAdd(t *testing.T) {
	mock := mo.MockSwVersionRxSwin{}
	services.GetDB().SetSwVersionRxSwin(&mock)

	tests := []mo.DBHttpTest{
		{
			Name: "Good data",
			Request: th.MakeTestRequest(http.MethodPost, "/manifests/sum/5236%2E12%2E50%2E67/rxswins", common.SwVersionRxSwinCreate{
				SwVersionRxSwins: []common.SwVersionRxSwin{
					{
						Version: "5236.12.50.67",
						RxSwin:  "testrxswin",
					},
					{
						Version: "5236.12.50.67",
						RxSwin:  "testrxswin2",
					},
				}}),
			ExpectedStatus:   http.StatusOK,
			ExpectedResponse: `[{"version":"5236.12.50.67","rxswin":"testrxswin"},{"version":"5236.12.50.67","rxswin":"testrxswin2"}]`,
		},
	}

	mo.RunParamHttpTests(t, tests, handlers.HandleUpdateManifestSUMSRxSwinsAdd, "/manifests/sum/:version/rxswins", &mock)
}
