Comments (12)
The error means that Abao calls the endpoint without defined url parameter param
. aka. Abao calls the endpoint like
curl http://host/my_resource/{param}
You should defined a example value of uriParameter param
in RAML or use a hook.
For defining in example in RAML,
/my_resource:
/{param}:
description: |
TBD.
uriParameters:
param:
description: |
The ID of resource
type: string
example: '1'
from abao.
RAML revised according to @cybertk's suggestion:
/my_resource/{param}:
description: |
TBD.
uriParameters:
param:
description: |
TBD.
type: string
example: '1033'
type:
collection-item:
exampleItem: !include my_resource-get-item.sample
One of the tests passes now! Thanks @cybertk!
GET /my_resource/{param} -> 200
✓ Validate response code and body (556ms)
GET /my_resource/{param} -> 500
1) Validate response code and body
1 passing (676ms)
1 failing
1) GET /my_resource/{param} -> 500 Validate response code and body:
Uncaught AssertionError: Got unexpected response code:
{ ... here, the API returned the expected object for a 200 okay ...}
Error: expected 200 to equal '500'
at Test.assertResponse (/usr/local/lib/node_modules/abao/lib/test.js:88:14)
at /usr/local/lib/node_modules/abao/lib/test.js:3:61
at /usr/local/lib/node_modules/abao/lib/test.js:70:11
at fn (/usr/local/lib/node_modules/abao/node_modules/async/lib/async.js:641:34)
at Object._onImmediate (/usr/local/lib/node_modules/abao/node_modules/async/lib/async.js:557:34)
at processImmediate [as _immediateCallback] (timers.js:345:15)
What is happening with the 500?
What does abao do to make the server return a 500?
Is it necessary to define something in the RAML that abao can use to create an incorrect request that returns a 500?
from abao.
It's not abao made server return a 500, in your test. Abao expected a 500 response, and your server returns 200 ok
In design, Abao will validate all response types defined in RAML, so in your case you should defined response 500
in your RAML
You can skip this test by using a hook and set test.skip = true
or send some real data to cause server returns 500
from abao.
Can you please give an example of how to define response 500 in the RAML?
Here is what I have. Can you tell me what is missing? Thanks!
resourceTypes:
- collection-item:
description: |
GET shows an individual <<resourcePathName|!singularize>>
get:
description: Get a list of <<resourcePathName>>.
responses:
200:
body:
application/json:
example: |
<<exampleItem>>
schema: !include my_resource-detail.schema
500:
body:
application/json:
example: |
{"message": "internal server error" }
schema: !include my_resource-detail.schema
from abao.
It's not about how to define response 500 in RAML, what you need to to is let your server returns 500, so that Abao can validate wether the response body is valid in this scene.
And to let your server returns 500, you need send some real data to server which can cause a 500.
from abao.
I can easily think of some real data which causes a 500 when sent to the server.
To cause a 500, we need to send an incorrect URL, for example /my_resource/bogus/1033
instead of /my_resource/1033
.
We can cause a 404 if we send bad data in a URI parameter, like /my_resource/ABCD
.
In these cases, how do I cause abao to send the bad input?
Where in the RAML should the data be, or how should the RAML reference the data?
from abao.
The Hook is used for this purpose.
First, you create a file hook.coffee
, and add the following contents in it:
{before, after} = require 'hooks'
before 'GET /my_resource/{param} -> 500', (test, done) ->
test.request.query =
color: 'red'
done()
Abao will send test.request
to your server, so you need some modifications on it.
Then, you should run Abao with hookfiles:
abao your_api.raml http://your_server --hookfiles=hook.coffee
from abao.
This is great, @cybertk, thank you!
Now, in the RAML, I have:
resourceTypes:
- collection-item:
description: |
GET shows an individual <<resourcePathName|!singularize>>
get:
description: Get a list of <<resourcePathName>>.
responses:
200:
body:
application/json:
example: |
<<exampleItem>>
schema: !include my_resource-detail.schema
404:
body:
application/json:
example: |
{"message": "Record not found: Couldn't find MyResource with id=ABCD" }
500:
body:
application/json:
example: |
{"message": "internal server error" }
And in hooks.coffee, two hooks:
{before, after} = require 'hooks'
before 'GET /my_resource/{param} -> 404', (test, done) ->
test.request.params =
param: 'ABCD'
done()
before 'GET /my_resource/{param} -> 500', (test, done) ->
test.request.params =
param: 'bogus/ABCD'
done()
And here is the result:
GET /ad_attributes/{id} -> 200
✓ Validate response code and body (576ms)
GET /ad_attributes/{id} -> 404
✓ Validate response code only (107ms)
GET /ad_attributes/{id} -> 500
✓ Validate response code only (748ms)
3 passing (1s)
Please close this issue. Thanks again!
from abao.
I am trying to get some endpoint tests to be skipped - adding 'test.skip = true' does not seem to work, and other than @Skip being initialised to false in the constructor of Test, I cannot see any reference to it.
Not sure if I misunderstand how to skip a test, or if this is a bug.
Any guidance would be appreciated.
Thanks.
from abao.
Could you share your hooks?
from abao.
An example of one of the hooks is as follows:
before 'DELETE /node/{node_id} -> 200', (test, done) ->
test.skip = true
done()
from abao.
test.skip = true doesn't work
from abao.
Related Issues (20)
- Make wrapper level for raml-parser
- Add RAML hook to skip tests HOT 4
- Make log-statements in hookfiles output reporter-specific content HOT 2
- Support For OpenAPI / swagger HOT 4
- First test case response time included beforeAll execute time HOT 1
- Rewrite in ES7 HOT 12
- Does not support resourceTypes
- ES7 Migration - Linting HOT 1
- ES7 Migration - CHANGELOG HOT 3
- ES7 Migration - CONTRIBUTING HOT 5
- ES7 Migration - Fixing package versions HOT 1
- Fails silently on valid RAML, even with names option HOT 10
- body disappears when header is added HOT 2
- Replace `tv4` JSON Schema validator
- Remove 'banUnknown' JSON Schema option
- Add error handling to request invocation
- Remove asserts from library source HOT 1
- Add standard User-Agent header
- Abao Tests Not Running HOT 28
- "before all" hook: TypeError: callback is not a function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from abao.