discount/internal/utils/transfer/calculation_test.go

94 lines
3.0 KiB
Go
Raw Normal View History

2023-07-04 04:04:31 +00:00
package transfer_test
import (
"testing"
"github.com/stretchr/testify/assert"
"penahub.gitlab.yandexcloud.net/pena-services/accruals-service/internal/models"
"penahub.gitlab.yandexcloud.net/pena-services/accruals-service/internal/proto/discount"
"penahub.gitlab.yandexcloud.net/pena-services/accruals-service/internal/utils/transfer"
)
func TestDiscountCalculationTargetProtoToModel(t *testing.T) {
t.Run("Перевод цели высчитывания из proto в модель", func(t *testing.T) {
assert.Equal(t,
&models.DiscountCalculationTarget{
TargetScope: models.TargetSum,
Products: []models.ProductTarget{
{ID: "1", Factor: 20},
{ID: "2", Factor: 20},
{ID: "3", Factor: 10},
},
Factor: 20,
},
transfer.DiscountCalculationTargetProtoToModel(&discount.DiscountCalculationTarget{
TargetScope: discount.TargetScope_Sum.Enum(),
Products: []*discount.ProductTarget{
{ID: "1", Factor: 20},
{ID: "2", Factor: 20},
{ID: "3", Factor: 10},
},
Factor: 20,
}),
)
})
t.Run("Перевод цели высчитывания из proto в модель с пустынми данными", func(t *testing.T) {
assert.Equal(t,
&models.DiscountCalculationTarget{
Products: []models.ProductTarget{},
TargetScope: models.TargetSum,
},
transfer.DiscountCalculationTargetProtoToModel(&discount.DiscountCalculationTarget{}),
)
})
t.Run("Перевод цели высчитывания из proto в модель с nil", func(t *testing.T) {
assert.Equal(t,
&models.DiscountCalculationTarget{TargetScope: models.TargetSum},
transfer.DiscountCalculationTargetProtoToModel(nil),
)
})
}
func TestDiscountCalculationTargetModelToProto(t *testing.T) {
t.Run("Перевод цели высчитывания из модели в proto", func(t *testing.T) {
assert.Equal(t,
&discount.DiscountCalculationTarget{
TargetScope: discount.TargetScope_Sum.Enum(),
Overhelm: new(bool),
TargetGroup: new(string),
Products: []*discount.ProductTarget{
{ID: "1", Factor: 20, Overhelm: new(bool)},
{ID: "2", Factor: 20, Overhelm: new(bool)},
{ID: "3", Factor: 10, Overhelm: new(bool)},
},
Factor: 20,
},
transfer.DiscountCalculationTargetModelToProto(models.DiscountCalculationTarget{
TargetScope: models.TargetSum,
Products: []models.ProductTarget{
{ID: "1", Factor: 20},
{ID: "2", Factor: 20},
{ID: "3", Factor: 10},
},
Factor: 20,
}),
)
})
t.Run("Перевод цели высчитывания из модели в proto с пустыми значениями", func(t *testing.T) {
assert.Equal(t,
&discount.DiscountCalculationTarget{
TargetScope: discount.TargetScope_Sum.Enum(),
Products: []*discount.ProductTarget{},
Overhelm: new(bool),
TargetGroup: new(string),
},
transfer.DiscountCalculationTargetModelToProto(models.DiscountCalculationTarget{
Products: []models.ProductTarget{},
}),
)
})
}