extract and parse where filter from Local.Aggregate
This was already working previously due to copy/paste from a place where
it had been already implemented, however it wasn't tested yet, so there
was no proper way of knowing for sure. Now we do.
@@ -28,6 +28,7 @@ type testCase struct {
resolverReturn interface{}
expectedResults []result
expectedGroupBy *common_filters.Path
+ expectedWhereFilter *common_filters.LocalFilter
}
type testCases []testCase
@@ -73,6 +74,57 @@ func Test_Resolve(t *testing.T) {
}},
},
+ testCase{
+ name: "single prop: mean with a where filter",
+ query: `{
+ Aggregate {
+ Things {
+ Car(
+ groupBy:["madeBy", "Manufacturer", "name"]
+ where: {
+ operator: LessThan,
+ valueInt: 200,
+ path: ["horsepower"],
+ }
+ ) {
+ horsepower {
+ mean
+ }
+ }
+ }
+ }
+ }`,
+ expectedProps: []Property{
+ {
+ Name: "horsepower",
+ Aggregators: []Aggregator{Mean},
+ },
+ },
+ resolverReturn: map[string]interface{}{
+ "horsepower": map[string]interface{}{
+ "mean": 275.7773,
+ },
+ },
+ expectedGroupBy: groupCarByMadeByManufacturerName(),
+ expectedResults: []result{{
+ pathToField: []string{"Aggregate", "Things", "Car", "horsepower", "mean"},
+ expectedValue: 275.7773,
+ }},
+ expectedWhereFilter: &common_filters.LocalFilter{
+ Root: &common_filters.Clause{
+ On: &common_filters.Path{
+ Class: schema.ClassName("Car"),
+ Property: schema.PropertyName("horsepower"),
+ },
+ Value: &common_filters.Value{
+ Value: 200,
+ Type: schema.DataTypeInt,
+ },
+ Operator: common_filters.OperatorLessThan,
+ },
+ },
+ },
+
testCase{
name: "all int props",
query: `{ Aggregate { Things { Car(groupBy:["madeBy", "Manufacturer", "name"]) { horsepower { mean, median, mode, maximum, minimum, count, sum } } } } }`,
@@ -153,6 +205,7 @@ func (tests testCases) AssertExtraction(t *testing.T, k kind.Kind, className str
ClassName: schema.ClassName(className),
Properties: testCase.expectedProps,
GroupBy: testCase.expectedGroupBy,
+ Filters: testCase.expectedWhereFilter,
}
resolver.On("LocalAggregate", expectedParams).
