-
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.
test: Add more ACP integration tests (#2583)
Resolves #2474 and #2475 Add integration tests for ACP on relation objects and `_avg` and `_count` methods.
- Loading branch information
1 parent
43cbf47
commit e4c59a9
Showing
4 changed files
with
671 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// 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 test_acp | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
acpUtils "github.com/sourcenetwork/defradb/tests/integration/acp" | ||
) | ||
|
||
func TestACP_QueryAverageWithoutIdentity(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Test acp, query average without identity", | ||
|
||
Actions: []any{ | ||
getSetupEmployeeCompanyActions(), | ||
|
||
testUtils.Request{ | ||
Request: ` | ||
query { | ||
_avg(Employee: {field: salary}) | ||
} | ||
`, | ||
Results: []map[string]any{ | ||
{ | ||
// 2 public employees, 1 with salary 10k, 1 with salary 20k | ||
"_avg": int(15000), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestACP_QueryAverageWithIdentity(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Test acp, query average with identity", | ||
|
||
Actions: []any{ | ||
getSetupEmployeeCompanyActions(), | ||
|
||
testUtils.Request{ | ||
Identity: acpUtils.Actor1Identity, | ||
Request: ` | ||
query { | ||
_avg(Employee: {field: salary}) | ||
} | ||
`, | ||
Results: []map[string]any{ | ||
{ | ||
// 4 employees with salaries 10k, 20k, 30k, 40k | ||
"_avg": int(25000), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestACP_QueryAverageWithWrongIdentity(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Test acp, query average without identity", | ||
|
||
Actions: []any{ | ||
getSetupEmployeeCompanyActions(), | ||
|
||
testUtils.Request{ | ||
Identity: acpUtils.Actor2Identity, | ||
Request: ` | ||
query { | ||
_avg(Employee: {field: salary}) | ||
} | ||
`, | ||
Results: []map[string]any{ | ||
{ | ||
// 2 public employees, 1 with salary 10k, 1 with salary 20k | ||
"_avg": int(15000), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |
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,183 @@ | ||
// 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 test_acp | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
acpUtils "github.com/sourcenetwork/defradb/tests/integration/acp" | ||
) | ||
|
||
func TestACP_QueryCountDocumentsWithoutIdentity(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Test acp, query documents' count without identity", | ||
|
||
Actions: []any{ | ||
getSetupEmployeeCompanyActions(), | ||
|
||
testUtils.Request{ | ||
Request: ` | ||
query { | ||
_count(Employee: {}) | ||
} | ||
`, | ||
Results: []map[string]any{ | ||
{ | ||
"_count": int(2), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestACP_QueryCountRelatedObjectsWithoutIdentity(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Test acp, query count of related objects without identity", | ||
|
||
Actions: []any{ | ||
getSetupEmployeeCompanyActions(), | ||
|
||
testUtils.Request{ | ||
Request: ` | ||
query { | ||
Company { | ||
_count(employees: {}) | ||
} | ||
} | ||
`, | ||
Results: []map[string]any{ | ||
{ | ||
// 1 of 2 companies is public and has 1 public employee out of 2 | ||
"_count": int(1), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestACP_QueryCountDocumentsWithIdentity(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Test acp, query documents' count with identity", | ||
|
||
Actions: []any{ | ||
getSetupEmployeeCompanyActions(), | ||
|
||
testUtils.Request{ | ||
Identity: acpUtils.Actor1Identity, | ||
Request: ` | ||
query { | ||
_count(Employee: {}) | ||
} | ||
`, | ||
Results: []map[string]any{ | ||
{ | ||
"_count": int(4), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestACP_QueryCountRelatedObjectsWithIdentity(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Test acp, query count of related objects with identity", | ||
|
||
Actions: []any{ | ||
getSetupEmployeeCompanyActions(), | ||
|
||
testUtils.Request{ | ||
Identity: acpUtils.Actor1Identity, | ||
Request: ` | ||
query { | ||
Company { | ||
_count(employees: {}) | ||
} | ||
} | ||
`, | ||
Results: []map[string]any{ | ||
{ | ||
"_count": int(2), | ||
}, | ||
{ | ||
"_count": int(2), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestACP_QueryCountDocumentsWithWrongIdentity(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Test acp, query documents' count without identity", | ||
|
||
Actions: []any{ | ||
getSetupEmployeeCompanyActions(), | ||
|
||
testUtils.Request{ | ||
Identity: acpUtils.Actor2Identity, | ||
Request: ` | ||
query { | ||
_count(Employee: {}) | ||
} | ||
`, | ||
Results: []map[string]any{ | ||
{ | ||
"_count": int(2), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestACP_QueryCountRelatedObjectsWithWrongIdentity(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Test acp, query count of related objects without identity", | ||
|
||
Actions: []any{ | ||
getSetupEmployeeCompanyActions(), | ||
|
||
testUtils.Request{ | ||
Identity: acpUtils.Actor2Identity, | ||
Request: ` | ||
query { | ||
Company { | ||
_count(employees: {}) | ||
} | ||
} | ||
`, | ||
Results: []map[string]any{ | ||
{ | ||
// 1 of 2 companies is public and has 1 public employee out of 2 | ||
"_count": int(1), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, test) | ||
} |
Oops, something went wrong.