Skip to content

Unit testing neo4j-driver errors #201

Closed
@pito-svk

Description

@pito-svk

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions