Testing Queries
Queries contain executable SQL that can be parameterized during execution by providing
a set of argument values. They can be tested via depot-test by using the DepotTest.check() step by providing additional
arguments data.
To write a Depot test that asserts on a query result, use the following syntax for actual parameter
(following up from the Query example):
DepotTest.in(pkg.mergedSchemas)
.setContent(path.join(__dirname, 'data'))
.check({
expectedUri: path.join(__dirname, 'expected'),
actual: [
{
schema: 'PersonCount',
arguments: {
country: 'England'
},
},
],
})
All expected checks are supported - file-based and programmatic assertions, count and exists checks, export, etc. The arguments will be converted where necessary, e.g. date/time can be provided as string:
.check({
...,
actual: [
{
schema: 'my.QuerySchema',
arguments: {
stringArg: 'myString',
intArg: 0,
dateArg: '2023-07-01',
dateTimeArg: '2023-07-01T12:00:00Z'
},
},
],
})
For programmatic retrieval of query contents, use DepotTest.getContent() and provide query arguments
via GetContent.bySchema(sourceSchema, arguments) parameter:
const scenario = DepotTest.in(petSchema)
.setContent(path.join(scenarioDirectory, 'data'))
.getContent({
schemas: {
'queryResults': GetContent.bySchema('my.QuerySchema', { stringArg: 'myString', boolArg: true })
}
});
const result = await scenario.run();
expect(result.returnedContent['queryResults']).toMatchObject([{ ... },...]);