85 lines
2.5 KiB
Go
85 lines
2.5 KiB
Go
![]() |
package expression_test
|
|||
|
|
|||
|
import (
|
|||
|
"testing"
|
|||
|
"time"
|
|||
|
|
|||
|
"github.com/stretchr/testify/assert"
|
|||
|
"go.mongodb.org/mongo-driver/bson"
|
|||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|||
|
|
|||
|
"penahub.gitlab.yandexcloud.net/pena-services/accruals-service/internal/fields"
|
|||
|
"penahub.gitlab.yandexcloud.net/pena-services/accruals-service/internal/models"
|
|||
|
"penahub.gitlab.yandexcloud.net/pena-services/accruals-service/internal/utils/expression"
|
|||
|
)
|
|||
|
|
|||
|
func TestGetAscRangeConditionBSON(t *testing.T) {
|
|||
|
t.Run("Получение bson условия диапазона от меньшего с заполненными данными", func(t *testing.T) {
|
|||
|
assert.Equal(t,
|
|||
|
[]bson.D{
|
|||
|
{{Key: "test", Value: bson.M{"$lte": "2020"}}},
|
|||
|
{{Key: "test", Value: nil}},
|
|||
|
},
|
|||
|
expression.GetAscRangeConditionBSON("test", "2020"),
|
|||
|
)
|
|||
|
assert.Equal(t,
|
|||
|
[]bson.D{
|
|||
|
{{Key: "test2", Value: bson.M{"$lte": 200.00}}},
|
|||
|
{{Key: "test2", Value: nil}},
|
|||
|
},
|
|||
|
expression.GetAscRangeConditionBSON("test2", 200.00),
|
|||
|
)
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
func TestGetValueConditionBSON(t *testing.T) {
|
|||
|
t.Run("Получение bson условия значения с заполненными данными", func(t *testing.T) {
|
|||
|
assert.Equal(t,
|
|||
|
[]bson.D{
|
|||
|
{{Key: "test", Value: "2020"}},
|
|||
|
{{Key: "test", Value: nil}},
|
|||
|
},
|
|||
|
expression.GetValueConditionBSON("test", "2020"),
|
|||
|
)
|
|||
|
assert.Equal(t,
|
|||
|
[]bson.D{
|
|||
|
{{Key: "test2", Value: 200.00}},
|
|||
|
{{Key: "test2", Value: nil}},
|
|||
|
},
|
|||
|
expression.GetValueConditionBSON("test2", 200.00),
|
|||
|
)
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
func TestGetPerionConditionBSON(t *testing.T) {
|
|||
|
|
|||
|
t.Run("Получение bson условия периода с заполненными данными", func(t *testing.T) {
|
|||
|
assert.Equal(t,
|
|||
|
[]bson.M{
|
|||
|
{
|
|||
|
"$and": []bson.D{
|
|||
|
{{Key: fields.PeriodCondition.From, Value: bson.M{"$lte": primitive.NewDateTimeFromTime(time.Unix(1674546287, 0).UTC())}}},
|
|||
|
{{Key: fields.PeriodCondition.To, Value: bson.M{"$gte": primitive.NewDateTimeFromTime(time.Unix(1674546287, 0).UTC())}}},
|
|||
|
},
|
|||
|
},
|
|||
|
{
|
|||
|
"$and": []bson.D{
|
|||
|
{{Key: fields.PeriodCondition.From, Value: nil}},
|
|||
|
{{Key: fields.PeriodCondition.To, Value: nil}},
|
|||
|
},
|
|||
|
},
|
|||
|
},
|
|||
|
expression.GetPerionConditionBSON(
|
|||
|
models.PeriodCondition{
|
|||
|
From: time.Unix(1674546287, 0).UTC(),
|
|||
|
To: time.Unix(1674546287, 0).UTC(),
|
|||
|
},
|
|||
|
expression.PeriodFieldPaths{
|
|||
|
From: fields.PeriodCondition.From,
|
|||
|
To: fields.PeriodCondition.To,
|
|||
|
},
|
|||
|
),
|
|||
|
)
|
|||
|
})
|
|||
|
}
|