package transfer_test import ( "testing" "github.com/stretchr/testify/assert" "penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models" "penahub.gitlab.yandexcloud.net/pena-services/customer/internal/proto/broker" "penahub.gitlab.yandexcloud.net/pena-services/customer/internal/utils/transfer" ) func TestPrivilegeModelToProto(t *testing.T) { t.Run("Успешный перевод модели привелегии в прото", func(t *testing.T) { assert.Equal(t, &broker.PrivilegeMessage{ PrivilegeID: "12", ServiceKey: "key-1", Type: "type", Value: "12", }, transfer.PrivilegeModelToProto(&models.Privilege{ ID: "1", Name: "name", PrivilegeID: "12", ServiceKey: "key-1", Description: "description", Type: "type", Value: "12", Price: 20, }), ) }) t.Run("Успешный перевод nil модели привелегии в прото", func(t *testing.T) { assert.Equal(t, &broker.PrivilegeMessage{}, transfer.PrivilegeModelToProto(nil)) }) } func TestPrivilegeArrayModelToProto(t *testing.T) { t.Run("Успешный перевод массива модели привелегий в массив прото", func(t *testing.T) { assert.Equal(t, []*broker.PrivilegeMessage{ { PrivilegeID: "12", ServiceKey: "key-1", Type: "type", Value: "12", }, }, transfer.PrivilegeArrayModelToProto([]models.Privilege{ { ID: "1", Name: "name", PrivilegeID: "12", ServiceKey: "key-1", Description: "description", Type: "type", Value: "12", Price: 20, }, }), ) }) } func TestPrivilegeProtoToModel(t *testing.T) { t.Run("Успешный перевод прото привелегии в модель", func(t *testing.T) { assert.Equal(t, &models.Privilege{ PrivilegeID: "12", ServiceKey: "key-1", Type: "type", Value: "12", }, transfer.PrivilegeProtoToModel(&broker.PrivilegeMessage{ PrivilegeID: "12", ServiceKey: "key-1", Type: "type", Value: "12", }), ) }) t.Run("Успешный перевод nil прото привелегии в модель", func(t *testing.T) { assert.Equal(t, &models.Privilege{}, transfer.PrivilegeProtoToModel(nil)) }) } func TestPrivilegeArrayProtoToModel(t *testing.T) { t.Run("Успешный перевод массива прото привелегий в массив моделей", func(t *testing.T) { assert.Equal(t, []models.Privilege{ { PrivilegeID: "12", ServiceKey: "key-1", Type: "type", Value: "12", }, {}, }, transfer.PrivilegeArrayProtoToModel([]*broker.PrivilegeMessage{ { PrivilegeID: "12", ServiceKey: "key-1", Type: "type", Value: "12", }, nil, }), ) }) }