package kafka_test

import (
	"testing"

	"github.com/fiskerinc/cloud-services/pkg/common"
	"github.com/fiskerinc/cloud-services/pkg/kafka"
	"github.com/fiskerinc/cloud-services/pkg/testhelper"
)

func TestErrUnhandledMessage(t *testing.T) {
	id := "11111111111111111"
	handler := "non_existent"
	payload := []byte(`{"data":"payload"}`)
	expectedTrexErr := `unhandled message, device: trex, id: 11111111111111111 handler: non_existent, payload: {"data":"payload"}`
	expectedHMIErr := `unhandled message, device: hmi, id: 11111111111111111 handler: non_existent, payload: [123 34 100 97 116 97 34 58 34 112 97 121 108 111 97 100 34 125]`

	err := kafka.ErrUnhandledMessage(common.TRex, id, handler, string(payload))
	if err.Error() != expectedTrexErr {
		t.Errorf(testhelper.TestErrorTemplate, "trex message", expectedTrexErr, err.Error())
	}

	err = kafka.ErrUnhandledMessage(common.HMI, id, handler, payload)
	if err.Error() != expectedHMIErr {
		t.Errorf(testhelper.TestErrorTemplate, "hmi message", expectedHMIErr, err.Error())
	}
}
