JonathanPrince / loopback-component-fixtures

handle fixtures for testing clients against
MIT License
12 stars 13 forks source link

Return 500 and show error details if fixture(s) fail to load #12

Closed persimmons closed 8 years ago

persimmons commented 8 years ago

When using Loopback validation or middleware, the fixtures setup will currently fail silently and show a success message even if fixtures failed to load.

This PR changes the output of the /api/fixtures/setup call to return a 500 with an array of error messages for each fixture that failed if at least one fixture fails.

I've added tests and adjusted the test config to add tests for this new behavior.

JonathanPrince commented 8 years ago

Hi @keithajackson, thank you for your contribution. Looks good to me, just one thing - are all tests passing for you? I don't get a details key on res.body.error, mine looks like:

{ 
  '0': {
    name: 'ValidationError',
    message: 'The `item` instance is not valid. Details: `requiredStuff` can\'t be blank (value: undefined).',
    statusCode: 422,
    details: { context: 'item', codes: [Object], messages: [Object] }
  },
  '1': { 
    name: 'ValidationError',
    message: 'The `item` instance is not valid. Details: `requiredStuff` can\'t be blank (value: undefined).',
    statusCode: 422,
    details: { context: 'item', codes: [Object], messages: [Object] }
  },
  status: 500,
  message: 'An unknown error occurred'
}
persimmons commented 8 years ago

Hi @JonathanPrince - thanks for your quick response! The tests are all passing on mine -- that is odd!

I played with a few things I thought might be the issue, but couldn't get my build to fail with any of them:

The res.body.error I get looks like this:

{ name: 'Error',
     status: 500,
     message: 'Failed with multiple errors, see `details` for more information.',
     details: [ [Object], [Object] ],
     stack: String
}

I wonder why this is -- any ideas of what we could try?

JonathanPrince commented 8 years ago

Hi @keithajackson, my apologies it was a dependency issue on my end, i should have taken a more thorough look at it before replying. Many thanks for your work, i'll merge and publish shortly.