Skip to content

Commit

Permalink
test: Add more ACP integration tests (#2583)
Browse files Browse the repository at this point in the history
Resolves #2474 and #2475

Add integration tests for ACP on relation objects and `_avg` and
`_count` methods.
  • Loading branch information
islamaliev authored May 3, 2024
1 parent 43cbf47 commit e4c59a9
Show file tree
Hide file tree
Showing 4 changed files with 671 additions and 0 deletions.
98 changes: 98 additions & 0 deletions tests/integration/acp/query/avg_test.go
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)
}
183 changes: 183 additions & 0 deletions tests/integration/acp/query/count_test.go
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)
}
Loading

0 comments on commit e4c59a9

Please sign in to comment.