Closed
Description
I would like to unit test my function which takes Neo4jError as first argument for example.
I have a function to properly format neo4j driver errors:
exports.formatErrors = () => {
return (err, req, res, next) => {
let error
if (err.fields) {
const singleError = err.fields[0]
const errorName = _.last(singleError.code.split('.'))
if (errorName === 'ConstraintValidationFailed') {
const field = singleError.message.split('"')[1]
error = new ValidationError(`${field} already exists`)
}
}
if (!error) error = err
next(error)
}
}
The point is, that I would like to mock this error for example:
Structure {
signature: 127,
fields:
[ { code: 'Neo.ClientError.Schema.ConstraintValidationFailed',
message: 'Node 0 already exists with label User and property "email"=[[email protected]]' } ] }
Is it possible to get Neo4jError class from this module and create error mock from this?
Thanks!
Metadata
Metadata
Assignees
Labels
No labels