package handlers_test

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

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

func TestHandleUpdateManifestSUMVersionRxSwinsGet(t *testing.T) {
	mock := mocks.MockSwVersionRxSwin{}
	services.GetDB().SetSwVersionRxSwin(&mock)
	svrs := []m.SwVersionRxSwin{{Version: "testv1", RxSwin: "trx1"}, {Version: "testv1", RxSwin: "trx2"}}

	tests := []mocks.DBHttpTest{
		{
			Name:             "Fetch all update manifest versions rows",
			Request:          th.MakeTestRequest(http.MethodGet, "/manifests/sum/5236%2E12%2E50%2E67/rxswins", nil),
			ExpectedStatus:   http.StatusOK,
			ExpectedResponse: `{"data":[{"version":"testv1","rxswin":"trx1"},{"version":"testv1","rxswin":"trx2"}],"total":2}`,
			DBTestCase: mocks.DBTestCase{
				SetupMockResponse: func() {
					mock.SelectResponse = svrs
				},
			},
		},
	}

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