-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add tests for foo_id field name clashes (#1521)
## Relevant issue(s) Resolves #1468 ## Description Adds tests for foo_id field name clashes with relational id fields.
- Loading branch information
1 parent
76b7c87
commit b24d5b4
Showing
2 changed files
with
205 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,88 @@ | ||
// Copyright 2022 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" | ||
) | ||
|
||
// This documents unwanted behaviour, see https://github.com/sourcenetwork/defradb/issues/1520 | ||
func TestQueryOneToManyWithIdFieldOnPrimary(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "One-to-many relation primary direction, id field with name clash on primary side", | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Book { | ||
name: String | ||
author_id: Int | ||
author: Author | ||
} | ||
type Author { | ||
name: String | ||
published: [Book] | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
// bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed | ||
CollectionID: 1, | ||
Doc: `{ | ||
"name": "John Grisham" | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
Doc: `{ | ||
"name": "Painted House", | ||
"author_id": 123456 | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 0, | ||
Doc: `{ | ||
"name": "A Time for Mercy", | ||
"author_id": "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed" | ||
}`, | ||
}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Book { | ||
name | ||
author_id | ||
author { | ||
name | ||
} | ||
} | ||
}`, | ||
Results: []map[string]any{ | ||
{ | ||
"name": "A Time for Mercy", | ||
"author_id": "bae-2edb7fdd-cad7-5ad4-9c7d-6920245a96ed", | ||
"author": map[string]any{ | ||
"name": "John Grisham", | ||
}, | ||
}, | ||
{ | ||
"name": "Painted House", | ||
"author_id": uint64(123456), | ||
"author": nil, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, []string{"Book", "Author"}, test) | ||
} |
117 changes: 117 additions & 0 deletions
117
tests/integration/query/one_to_one/with_id_field_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,117 @@ | ||
// Copyright 2022 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_one | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestQueryOneToOneWithIdFieldOnSecondary(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "One-to-one relation secondary direction, id field with name clash on secondary side", | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Book { | ||
name: String | ||
author_id: Int | ||
author: Author | ||
} | ||
type Author { | ||
name: String | ||
published: Book @primary | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
// bae-d82dbe47-9df1-5e33-bd87-f92e9c378161 | ||
CollectionID: 0, | ||
Doc: `{ | ||
"name": "Painted House", | ||
"author_id": 123456 | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 1, | ||
Doc: `{ | ||
"name": "John Grisham", | ||
"published_id": "bae-d82dbe47-9df1-5e33-bd87-f92e9c378161" | ||
}`, | ||
}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Book { | ||
name | ||
author_id | ||
author { | ||
name | ||
} | ||
} | ||
}`, | ||
Results: []map[string]any{ | ||
{ | ||
"name": "Painted House", | ||
"author_id": uint64(123456), | ||
"author": map[string]any{ | ||
"name": "John Grisham", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, []string{"Book", "Author"}, test) | ||
} | ||
|
||
// This documents unwanted behaviour, see https://github.com/sourcenetwork/defradb/issues/1520 | ||
func TestQueryOneToOneWithIdFieldOnPrimary(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "One-to-one relation primary direction, id field with name clash on primary side", | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Book { | ||
name: String | ||
author_id: Int | ||
author: Author @primary | ||
} | ||
type Author { | ||
name: String | ||
published: Book | ||
} | ||
`, | ||
}, | ||
testUtils.CreateDoc{ | ||
// bae-d82dbe47-9df1-5e33-bd87-f92e9c378161 | ||
CollectionID: 0, | ||
Doc: `{ | ||
"name": "Painted House", | ||
"author_id": 123456 | ||
}`, | ||
}, | ||
testUtils.CreateDoc{ | ||
CollectionID: 1, | ||
Doc: `{ | ||
"name": "John Grisham", | ||
"published_id": "bae-d82dbe47-9df1-5e33-bd87-f92e9c378161" | ||
}`, | ||
ExpectedError: "value doesn't contain number; it contains string", | ||
}, | ||
}, | ||
} | ||
|
||
testUtils.ExecuteTestCase(t, []string{"Book", "Author"}, test) | ||
} |