Some checks are pending
Automatisch Backend Tests / test (push) Waiting to run
Automatisch CI / linter (push) Waiting to run
Automatisch CI / start-backend-server (push) Waiting to run
Automatisch CI / start-backend-worker (push) Waiting to run
Automatisch CI / build-web (push) Waiting to run
Automatisch UI Tests / test (push) Waiting to run
32 lines
831 B
JavaScript
32 lines
831 B
JavaScript
import { ValidationError } from 'objection';
|
|
|
|
export const toRequireProperty = async (model, requiredProperty) => {
|
|
try {
|
|
await model.query().insert({});
|
|
} catch (error) {
|
|
if (
|
|
error instanceof ValidationError &&
|
|
error.message.includes(
|
|
`${requiredProperty}: must have required property '${requiredProperty}'`
|
|
)
|
|
) {
|
|
return {
|
|
pass: true,
|
|
message: () =>
|
|
`Expected ${requiredProperty} to be required, and it was.`,
|
|
};
|
|
} else {
|
|
return {
|
|
pass: false,
|
|
message: () =>
|
|
`Expected ${requiredProperty} to be required, but it was not found in the error message.`,
|
|
};
|
|
}
|
|
}
|
|
return {
|
|
pass: false,
|
|
message: () =>
|
|
`Expected ${requiredProperty} to be required, but no ValidationError was thrown.`,
|
|
};
|
|
};
|