package hwversion

import (
	"encoding/json"
	"testing"

	"github.com/fiskerinc/cloud-services/pkg/common"
	"github.com/fiskerinc/cloud-services/pkg/db/queries/mocks"
	"github.com/go-playground/assert/v2"
)

func TestSetHWVersion(t *testing.T) {
	manifest := &common.UpdateManifest{
		ECUs: []*common.UpdateManifestECU{{ECU: "TREX", HWVersions: []string{"TREXHW"}}, {ECU: "PKC", HWVersions: []string{"vPKC1", "vPKC2"}}, {ECU: "ADAS", HWVersions: []string{"adas", "adas2"}}},
	}
	mockCarsDB := mocks.MockCars{}
	mockCarsDB.SelectCarECUs = []common.CarECU{{ECU: "PKC", HWVersion: "vPKC1"}, {ECU: "ADAS", HWVersion: "adas2"}}
	err := SetHWVersion(manifest, "somevin", &mockCarsDB)

	if err != nil {
		t.Error(err)
	}

	expectedOutPut := &common.UpdateManifest{
		ECUs: []*common.UpdateManifestECU{{ECU: "TREX", HWVersion: "placeholder"}, {ECU: "PKC", HWVersion: "vPKC1"}, {ECU: "ADAS", HWVersion: "adas2"}},
	}

	a, _ := json.Marshal(manifest.ECUs)
	b, _ := json.Marshal(expectedOutPut.ECUs)
	assert.Equal(t, string(a), string(b))
}
