143 lines
4.4 KiB
Go
143 lines
4.4 KiB
Go
![]() |
package transfer_test
|
|||
|
|
|||
|
import (
|
|||
|
"testing"
|
|||
|
"time"
|
|||
|
|
|||
|
"github.com/stretchr/testify/assert"
|
|||
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|||
|
|
|||
|
"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 TestDiscountConditionProtoToModel(t *testing.T) {
|
|||
|
userID := "1"
|
|||
|
userType := "nkvo"
|
|||
|
coupon := "test"
|
|||
|
product := "product1"
|
|||
|
purchasesAmount := float64(20000)
|
|||
|
cartPurchasesAmount := float64(20000)
|
|||
|
term := uint64(20)
|
|||
|
usage := uint64(20)
|
|||
|
priceFrom := float64(20000)
|
|||
|
group := "testGroup"
|
|||
|
|
|||
|
t.Run("Перевод не до конца заполненных условий скидок с proto в модель", func(t *testing.T) {
|
|||
|
assert.Equal(t,
|
|||
|
&models.DiscountCondition{CartPurchasesAmount: &cartPurchasesAmount},
|
|||
|
transfer.DiscountConditionProtoToModel(&discount.DiscountCondition{
|
|||
|
CartPurchasesAmount: &cartPurchasesAmount,
|
|||
|
}),
|
|||
|
)
|
|||
|
})
|
|||
|
|
|||
|
t.Run("Перевод скидок с nil proto в модель", func(t *testing.T) {
|
|||
|
assert.Equal(t, &models.DiscountCondition{}, transfer.DiscountConditionProtoToModel(nil))
|
|||
|
})
|
|||
|
|
|||
|
t.Run("Перевод условий скидок с proto в модель", func(t *testing.T) {
|
|||
|
assert.Equal(t,
|
|||
|
&models.DiscountCondition{
|
|||
|
CartPurchasesAmount: &cartPurchasesAmount,
|
|||
|
User: &userID,
|
|||
|
UserType: &userType,
|
|||
|
PurchasesAmount: &purchasesAmount,
|
|||
|
Coupon: &coupon,
|
|||
|
Product: &product,
|
|||
|
Term: &term,
|
|||
|
Usage: &usage,
|
|||
|
PriceFrom: &priceFrom,
|
|||
|
Group: &group,
|
|||
|
Period: &models.PeriodCondition{
|
|||
|
From: time.Unix(1674546287, 0).UTC(),
|
|||
|
To: time.Unix(1674546287, 0).UTC(),
|
|||
|
},
|
|||
|
},
|
|||
|
transfer.DiscountConditionProtoToModel(&discount.DiscountCondition{
|
|||
|
CartPurchasesAmount: &cartPurchasesAmount,
|
|||
|
User: &userID,
|
|||
|
UserType: &userType,
|
|||
|
PurchasesAmount: &purchasesAmount,
|
|||
|
Coupon: &coupon,
|
|||
|
Product: &product,
|
|||
|
Term: &term,
|
|||
|
Usage: &usage,
|
|||
|
PriceFrom: &priceFrom,
|
|||
|
Group: &group,
|
|||
|
Period: &discount.PeriodCondition{
|
|||
|
From: ×tamppb.Timestamp{
|
|||
|
Seconds: 1674546287,
|
|||
|
Nanos: 0,
|
|||
|
},
|
|||
|
To: ×tamppb.Timestamp{
|
|||
|
Seconds: 1674546287,
|
|||
|
Nanos: 0,
|
|||
|
},
|
|||
|
},
|
|||
|
}),
|
|||
|
)
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
func TestDiscountConditionModelToProto(t *testing.T) {
|
|||
|
userID := "1"
|
|||
|
userType := "nkvo"
|
|||
|
coupon := "test"
|
|||
|
product := "product1"
|
|||
|
purchasesAmount := float64(20000)
|
|||
|
cartPurchasesAmount := float64(20000)
|
|||
|
term := uint64(20)
|
|||
|
usage := uint64(20)
|
|||
|
priceFrom := float64(20000)
|
|||
|
group := "testGroup"
|
|||
|
|
|||
|
t.Run("Перевод условий скидки с модели в proto", func(t *testing.T) {
|
|||
|
assert.Equal(t,
|
|||
|
&discount.DiscountCondition{
|
|||
|
CartPurchasesAmount: &cartPurchasesAmount,
|
|||
|
User: &userID,
|
|||
|
UserType: &userType,
|
|||
|
PurchasesAmount: &purchasesAmount,
|
|||
|
Coupon: &coupon,
|
|||
|
Product: &product,
|
|||
|
Term: &term,
|
|||
|
Usage: &usage,
|
|||
|
PriceFrom: &priceFrom,
|
|||
|
Group: &group,
|
|||
|
Period: &discount.PeriodCondition{
|
|||
|
From: ×tamppb.Timestamp{
|
|||
|
Seconds: 1674546287,
|
|||
|
Nanos: 0,
|
|||
|
},
|
|||
|
To: ×tamppb.Timestamp{
|
|||
|
Seconds: 1674546287,
|
|||
|
Nanos: 0,
|
|||
|
},
|
|||
|
},
|
|||
|
},
|
|||
|
transfer.DiscountConditionModelToProto(&models.DiscountCondition{
|
|||
|
CartPurchasesAmount: &cartPurchasesAmount,
|
|||
|
User: &userID,
|
|||
|
UserType: &userType,
|
|||
|
PurchasesAmount: &purchasesAmount,
|
|||
|
Coupon: &coupon,
|
|||
|
Product: &product,
|
|||
|
Term: &term,
|
|||
|
Usage: &usage,
|
|||
|
PriceFrom: &priceFrom,
|
|||
|
Group: &group,
|
|||
|
Period: &models.PeriodCondition{
|
|||
|
From: time.Unix(1674546287, 0).UTC(),
|
|||
|
To: time.Unix(1674546287, 0).UTC(),
|
|||
|
},
|
|||
|
}),
|
|||
|
)
|
|||
|
})
|
|||
|
|
|||
|
t.Run("Перевод условий скидки с nil модели в proto", func(t *testing.T) {
|
|||
|
assert.Nil(t, transfer.DiscountConditionModelToProto(nil))
|
|||
|
})
|
|||
|
}
|