mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
42 lines
658 B
Go
42 lines
658 B
Go
package query
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestParseExpression(t *testing.T) {
|
|
json := `{
|
|
"$and": [
|
|
{
|
|
"$match": {
|
|
"account": "accounts::pending"
|
|
}
|
|
},
|
|
{
|
|
"$or": [
|
|
{
|
|
"$gte": {
|
|
"balance": 1000
|
|
}
|
|
},
|
|
{
|
|
"$match": {
|
|
"metadata[category]": "gold"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}`
|
|
expr, err := ParseJSON(json)
|
|
require.NoError(t, err)
|
|
|
|
_, _, err = expr.Build(ContextFn(func(key, operator string, value any) (string, []any, error) {
|
|
return fmt.Sprintf("%s %s ?", key, DefaultComparisonOperatorsMapping[operator]), []any{value}, nil
|
|
}))
|
|
require.NoError(t, err)
|
|
}
|