specHelper should allow response metadata to be turned off
See original GitHub issueWhen using specHelper, test server rules for response metadata are not respected
- ActionHero Version:
15.1.0
- Node.js Version:
4.5.0
- Operating System
OSX
Issue description
When running a unit tests with specHelper, it would be helpful if we could turn off response metadata, because it can interfere with testing the expected responses. An example of how this affects testing is as follows:
I have an action that returns a json array as a response, if I cannot turn off my metadata, the array I get back looks like:
[ { id: 'f05f9d0a-6587-4672-8467-d02f7e525e63', name: 'My Box', path: 'app/my-box', category_id: 'f7ff85a0-faaa-11e5-a8a9-7fa3b294cd46' }, { id: '498efd35-f17a-47e6-a365-f5a3a075911e', name: 'My Box Other', path: 'app/my-box-other', category_id: 'f7ff85a0-faaa-11e5-a8a9-7fa3b294cd46' }, messageCount: 1, serverInformation: { serverName: 'cerberus-mock-api', apiVersion: '0.0.1' }, requesterInformation: { id: 'b263bbc5-9d4b-4cd8-8c96-e125d448baf3', remoteIP: 'testServer', receivedParams: { action: 'getSafeDepositBoxList', apiVersion: 1 } } ]
This means that in order to get the actual response, I have to do something like:
var trueResponse = [response[0], response[1]];
Which is not ideal. And it gets even worse for when I want to test for an empty array as a response.
In all cases where I run an actual server, these are properties I can turn off, but digging into the specHelper code, there is no way to turn this off for this mock server functionality. Ideally it should either have its own config setting that it decides on, or it should respect the test settings, or it should be able to take an options argument.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
And now, the actual solve to the question you initially asked: https://github.com/evantahler/actionhero/pull/980
api.specHelper.returnMetadata = false
The first thing that this issue points out is that we are aren’t being “type safe” (as safe as you can be in JS) with regard to our error handling and metadata in the SpecHelper.
We shouldn’t do things like
data.response.error = error
iftypeof data.response === 'string'
!This should help that https://github.com/evantahler/actionhero/pull/979