-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
tests/integration/query/one_to_many/with_count_order_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2024 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package one_to_many | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestQueryOneToMany_WithCountAliasOrder_ShouldOrderResults(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "One-to-many relation query from many side with order alias", | ||
Actions: []any{ | ||
testUtils.CreateDoc{ | ||
CollectionID: 1, | ||
Doc: `{ | ||
"name": "John Grisham", | ||
"age": 65, | ||
"verified": true | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 1, | ||
Doc: `{ | ||
"name": "Cornelia Funke", | ||
"age": 62, | ||
"verified": false | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
DocMap: map[string]any{ | ||
"name": "Painted House", | ||
"rating": 4.9, | ||
"author_id": testUtils.NewDocIndex(1, 0), | ||
}, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
DocMap: map[string]any{ | ||
"name": "A Time for Mercy", | ||
"rating": 4.5, | ||
"author_id": testUtils.NewDocIndex(1, 0), | ||
}, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
DocMap: map[string]any{ | ||
"name": "Theif Lord", | ||
"rating": 4.8, | ||
"author_id": testUtils.NewDocIndex(1, 1), | ||
}, | ||
}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Author(order: {_alias: {publishedCount: DESC}}) { | ||
name | ||
publishedCount: _count(published: {}) | ||
} | ||
}`, | ||
Results: map[string]any{ | ||
"Author": []map[string]any{ | ||
{ | ||
"name": "John Grisham", | ||
"publishedCount": int64(2), | ||
}, | ||
{ | ||
"name": "Cornelia Funke", | ||
"publishedCount": int64(1), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} |
95 changes: 95 additions & 0 deletions
95
tests/integration/query/one_to_many/with_sum_order_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright 2024 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package one_to_many | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestQueryOneToMany_WithSumWithAliasOrder_ShouldOrderResults(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "One-to-many relation query from many side with sum with order alias", | ||
Actions: []any{ | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
Doc: `{ | ||
"name": "Painted House", | ||
"rating": 4.9, | ||
"author_id": "bae-e1ea288f-09fa-55fa-b0b5-0ac8941ea35b" | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
Doc: `{ | ||
"name": "A Time for Mercy", | ||
"rating": 4.5, | ||
"author_id": "bae-e1ea288f-09fa-55fa-b0b5-0ac8941ea35b" | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
Doc: `{ | ||
"name": "The Associate", | ||
"rating": 4.2, | ||
"author_id": "bae-e1ea288f-09fa-55fa-b0b5-0ac8941ea35b" | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
Doc: `{ | ||
"name": "Theif Lord", | ||
"rating": 4.8, | ||
"author_id": "bae-72e8c691-9f20-55e7-9228-8af1cf54cace" | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 1, | ||
Doc: `{ | ||
"name": "John Grisham", | ||
"age": 65, | ||
"verified": true | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 1, | ||
Doc: `{ | ||
"name": "Cornelia Funke", | ||
"age": 62, | ||
"verified": false | ||
}`, | ||
}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Author(order: {_alias: {totalRating: DESC}}) { | ||
name | ||
totalRating: _sum(published: {field: rating}) | ||
} | ||
}`, | ||
Results: map[string]any{ | ||
"Author": []map[string]any{ | ||
{ | ||
"name": "John Grisham", | ||
"totalRating": 13.600000000000001, | ||
}, | ||
{ | ||
"name": "Cornelia Funke", | ||
"totalRating": 4.8, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} |