customer/internal/utils/transfer/tariff_test.go

106 lines
3.0 KiB
Go
Raw Normal View History

2023-05-30 11:33:57 +00:00
package transfer_test
import (
"testing"
"github.com/stretchr/testify/assert"
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
2023-07-06 18:50:46 +00:00
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/proto/broker"
2023-05-30 11:33:57 +00:00
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/proto/discount"
"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/utils/transfer"
)
func TestTariffsToProductInformations(t *testing.T) {
t.Run("Успешный перевод массива моделей тарифов в массив информации о продуктах", func(t *testing.T) {
assert.Equal(t,
[]*discount.ProductInformation{
{ID: "1", Price: 20},
{ID: "2", Price: 10},
},
transfer.TariffsToProductInformations([]models.Tariff{
{ID: "1", Price: 20},
{ID: "2", Price: 10},
}),
)
})
}
2023-07-06 18:50:46 +00:00
func TestTariffToProductInformation(t *testing.T) {
t.Run("Успешный перевод модели тарифа в информацию о продукте", func(t *testing.T) {
assert.Equal(t,
&discount.ProductInformation{
ID: "1",
Price: 20,
},
transfer.TariffToProductInformation(models.Tariff{
ID: "1",
Price: 20,
}),
)
})
}
func TestTariffMessageProtoToTariffModel(t *testing.T) {
t.Run("Успешный перевод прото сообщения тарифа в модель", func(t *testing.T) {
assert.Equal(t,
&models.Tariff{
Privileges: []models.Privilege{
{
PrivilegeID: "12",
ServiceKey: "key-1",
2023-08-02 14:22:50 +00:00
Type: models.PrivilegeTypeCount,
2023-07-06 18:50:46 +00:00
Value: "12",
},
},
},
transfer.TariffMessageProtoToTariffModel(&broker.TariffMessage{
UserID: "11",
Privileges: []*broker.PrivilegeMessage{
{
PrivilegeID: "12",
ServiceKey: "key-1",
2023-08-02 14:22:50 +00:00
Type: broker.PrivilegeType_Count,
2023-07-06 18:50:46 +00:00
Value: "12",
},
},
}),
)
})
t.Run("Успешный перевод nil прото сообщения тарифа в модель", func(t *testing.T) {
assert.Equal(t, &models.Tariff{}, transfer.TariffMessageProtoToTariffModel(nil))
})
}
func TestTariffModelToProtoMessage(t *testing.T) {
t.Run("Успешный перевод модели тарифа в прото сообщение", func(t *testing.T) {
assert.Equal(t,
&broker.TariffMessage{
UserID: "1",
Privileges: []*broker.PrivilegeMessage{
{
PrivilegeID: "12",
ServiceKey: "key-1",
2023-08-02 14:22:50 +00:00
Type: broker.PrivilegeType_Count,
2023-07-06 18:50:46 +00:00
Value: "12",
},
},
},
transfer.TariffModelToProtoMessage("1", &models.Tariff{
Privileges: []models.Privilege{
{
PrivilegeID: "12",
ServiceKey: "key-1",
2023-08-02 14:22:50 +00:00
Type: models.PrivilegeTypeCount,
2023-07-06 18:50:46 +00:00
Value: "12",
},
},
}),
)
})
t.Run("Успешный перевод nil модели тарифа в прото сообщение", func(t *testing.T) {
assert.Equal(t, &broker.TariffMessage{}, transfer.TariffModelToProtoMessage("1", nil))
})
}