GithubHelp home page GithubHelp logo

abao fails to send URI parameter about abao HOT 12 CLOSED

cybertk avatar cybertk commented on June 10, 2024
abao fails to send URI parameter

from abao.

Comments (12)

cybertk avatar cybertk commented on June 10, 2024

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.

scordatura avatar scordatura commented on June 10, 2024

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.

cybertk avatar cybertk commented on June 10, 2024

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.

scordatura avatar scordatura commented on June 10, 2024

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.

cybertk avatar cybertk commented on June 10, 2024

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.

scordatura avatar scordatura commented on June 10, 2024

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.

cybertk avatar cybertk commented on June 10, 2024

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.

scordatura avatar scordatura commented on June 10, 2024

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.

smt-pi avatar smt-pi commented on June 10, 2024

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.

cybertk avatar cybertk commented on June 10, 2024

Could you share your hooks?

from abao.

smt-pi avatar smt-pi commented on June 10, 2024

An example of one of the hooks is as follows:

before 'DELETE /node/{node_id} -> 200', (test, done) ->
  test.skip = true
  done()

from abao.

sprakasam avatar sprakasam commented on June 10, 2024

test.skip = true doesn't work

from abao.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.