aquadoggo
aquadoggo copied to clipboard
High-level test db that creates materialised documents
For testing the GraphQL API I would like to have a high-level alternative to test_db
that can create application schemas and documents in the test db that use these schemas. It should also materialise these documents.
It could have an api similar to this:
fn new_test(
#[from(test_db_with_documents)]
#[with(
// Creates application schemas
vec![
// Publishes and materialises a schema `schema_name` with the given field definitions
("schema_name", vec![("field_name", FieldType::Boolean)]),
// More schemas could be created here...
]
// Creates documents for the created schemas
vec![
// First document uses the just created `schema_name` schema
("schema_name", vec![
create_operation(vec![("field_name", OperationValue::Boolean(true))])
]),
// Second document uses a system schema and includes an update operation
(&SchemaId::SomeSystemSchema(1).as_str(), vec![
create_operation(vec![...]),
update_operation(vec![...])
])
]
)]
runner: TestDatabaseRunner,
)
Nice! We will need something like this soon everywhere when we validate incoming operations against stored schema.
Node
in p2panda-rs performs materialisation, so maybe this can be used in some way.