94 lines
3.1 KiB
Go
94 lines
3.1 KiB
Go
![]() |
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{},
|
|||
|
}),
|
|||
|
)
|
|||
|
})
|
|||
|
}
|