2023-07-04 04:04:31 +00:00
|
|
|
|
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 := "nkvo11"
|
|
|
|
|
coupon := "test22"
|
|
|
|
|
product := "product13"
|
|
|
|
|
purchasesAmount := uint64(20000)
|
|
|
|
|
cartPurchasesAmount := uint64(20000)
|
|
|
|
|
term := uint64(20)
|
|
|
|
|
usage := uint64(20)
|
|
|
|
|
priceFrom := uint64(20000)
|
|
|
|
|
group := "testGroupo"
|
|
|
|
|
|
|
|
|
|
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 := uint64(20000)
|
|
|
|
|
cartPurchasesAmount := uint64(20000)
|
|
|
|
|
term := uint64(20)
|
|
|
|
|
usage := uint64(20)
|
|
|
|
|
priceFrom := uint64(20000)
|
|
|
|
|
group := "testGroupbgfbgbgb"
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
})
|
|
|
|
|
}
|