-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add test for deletion of records in a relationship (#329)
resolves #221 These are non-transactional tests. Should have some transactional tests too (@todo #328).
- Loading branch information
1 parent
41dbd5a
commit deb2ffd
Showing
5 changed files
with
244 additions
and
7 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,20 @@ | ||
## Testing Guide | ||
|
||
- We want to keep the mutation and query tests separate, here is what the folder | ||
structure looks like currently: | ||
``` | ||
db/tests | ||
├── mutation/ | ||
└── query/ | ||
``` | ||
|
||
- Every immediate directory under `db/tests/mutation` and `db/tests/query` should ONLY contain | ||
a single schema. For example: | ||
`db/tests/query/simple` and `db/tests/query/complex` have different schemas. | ||
|
||
- We can group different types of tests using the same schema into further sub-folders. | ||
For example: | ||
- `db/tests/mutation/simple/create`: contains tests that | ||
use the `simple` schema to test only the create mutation. | ||
- `db/tests/mutation/simple/mix`: contains test that use | ||
the `simple` schema to test combination of mutations. |
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,169 @@ | ||
// 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 relation_delete | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/db/tests" | ||
relationTests "github.com/sourcenetwork/defradb/db/tests/mutation/relation" | ||
) | ||
|
||
func TestRelationalDeletionOfADocumentUsingSingleKey_Success(t *testing.T) { | ||
tests := []testUtils.QueryTestCase{ | ||
|
||
{ | ||
Description: "Relational delete mutation where one element exists.", | ||
Query: `mutation { | ||
delete_author(id: "bae-2f80f359-535d-508e-ba58-088a309ce3c3") { | ||
_key | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
// Books | ||
0: { | ||
// bae-80eded16-ee4b-5c9d-b33f-6a7b83958af2 | ||
(`{ | ||
"name": "100 Go Mistakes to Avoid.", | ||
"rating": 4.8, | ||
"publisher_id": "bae-176ebdf0-77e7-5b2f-91ae-f620e37a29e3" | ||
}`)}, | ||
// Authors | ||
1: { | ||
// bae-2f80f359-535d-508e-ba58-088a309ce3c3 | ||
(`{ | ||
"name": "Teiva Harsanyi", | ||
"age": 48, | ||
"verified": true, | ||
"wrote_id": "bae-80eded16-ee4b-5c9d-b33f-6a7b83958af2" | ||
}`)}, | ||
// Publishers | ||
2: { | ||
// bae-176ebdf0-77e7-5b2f-91ae-f620e37a29e3 | ||
(`{ | ||
"name": "Manning Early Access Program (MEAP)", | ||
"address": "Online" | ||
}`)}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"_key": "bae-2f80f359-535d-508e-ba58-088a309ce3c3", | ||
}, | ||
}, | ||
ExpectedError: "", | ||
}, | ||
|
||
{ | ||
Description: "Relational delete mutation with an aliased _key name.", | ||
Query: `mutation { | ||
delete_author(id: "bae-2f80f359-535d-508e-ba58-088a309ce3c3") { | ||
AliasOfKey: _key | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
// Books | ||
0: { | ||
// bae-80eded16-ee4b-5c9d-b33f-6a7b83958af2 | ||
(`{ | ||
"name": "100 Go Mistakes to Avoid.", | ||
"rating": 4.8, | ||
"publisher_id": "bae-176ebdf0-77e7-5b2f-91ae-f620e37a29e3" | ||
}`)}, | ||
// Authors | ||
1: { | ||
// bae-2f80f359-535d-508e-ba58-088a309ce3c3 | ||
(`{ | ||
"name": "Teiva Harsanyi", | ||
"age": 48, | ||
"verified": true, | ||
"wrote_id": "bae-80eded16-ee4b-5c9d-b33f-6a7b83958af2" | ||
}`)}, | ||
// Publishers | ||
2: { | ||
// bae-176ebdf0-77e7-5b2f-91ae-f620e37a29e3 | ||
(`{ | ||
"name": "Manning Early Access Program (MEAP)", | ||
"address": "Online" | ||
}`)}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"AliasOfKey": "bae-2f80f359-535d-508e-ba58-088a309ce3c3", | ||
}, | ||
}, | ||
ExpectedError: "", | ||
}, | ||
|
||
{ | ||
Description: "Relational Delete of an updated document and an aliased _key name.", | ||
Query: `mutation { | ||
delete_author(id: "bae-2f80f359-535d-508e-ba58-088a309ce3c3") { | ||
Key: _key | ||
} | ||
}`, | ||
|
||
Docs: map[int][]string{ | ||
// Books | ||
0: { | ||
// bae-80eded16-ee4b-5c9d-b33f-6a7b83958af2 | ||
(`{ | ||
"name": "100 Go Mistakes to Avoid.", | ||
"rating": 4.8, | ||
"publisher_id": "bae-176ebdf0-77e7-5b2f-91ae-f620e37a29e3" | ||
}`), | ||
}, | ||
|
||
// Authors | ||
1: { | ||
// bae-2f80f359-535d-508e-ba58-088a309ce3c3 | ||
(`{ | ||
"name": "Teiva Harsanyi", | ||
"age": 48, | ||
"verified": true, | ||
"wrote_id": "bae-80eded16-ee4b-5c9d-b33f-6a7b83958af2" | ||
}`), | ||
}, | ||
|
||
// Publishers | ||
2: { | ||
// bae-176ebdf0-77e7-5b2f-91ae-f620e37a29e3 | ||
(`{ | ||
"name": "Manning Early Access Program (MEAP)", | ||
"address": "Online" | ||
}`), | ||
|
||
// bae-5c599633-d6d2-56ae-b3f0-1b65b4cee9fe | ||
(`{ | ||
"name": "Manning Publications", | ||
"address": "Website" | ||
}`), | ||
}, | ||
}, | ||
Updates: map[int][]string{ | ||
0: { | ||
(`{ | ||
"name": "Rust in Action.", | ||
"publisher_id": "bae-5c599633-d6d2-56ae-b3f0-1b65b4cee9fe" | ||
}`)}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"Key": "bae-2f80f359-535d-508e-ba58-088a309ce3c3", | ||
}, | ||
}, | ||
ExpectedError: "", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
relationTests.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,48 @@ | ||
// 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 relation | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/db/tests" | ||
) | ||
|
||
var bookAuthorPublisherGQLSchema = (` | ||
type book { | ||
name: String | ||
rating: Float | ||
author: author | ||
publisher: publisher | ||
} | ||
type author { | ||
name: String | ||
age: Int | ||
verified: Boolean | ||
wrote: book @primary | ||
} | ||
type publisher { | ||
name: String | ||
address: String | ||
published: book | ||
} | ||
`) | ||
|
||
func ExecuteTestCase(t *testing.T, test testUtils.QueryTestCase) { | ||
testUtils.ExecuteQueryTestCase( | ||
t, | ||
bookAuthorPublisherGQLSchema, | ||
[]string{"book", "author", "publisher"}, | ||
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
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