Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expect_json_types for elements of an array not working #94

Open
vjster opened this issue Apr 15, 2016 · 4 comments
Open

expect_json_types for elements of an array not working #94

vjster opened this issue Apr 15, 2016 · 4 comments

Comments

@vjster
Copy link

vjster commented Apr 15, 2016

Hi,
I want to validate the json schema for an array and it's elements but I'm unable to do that with Airborne. Continuously getting errors.

Here is part of my data :-

description: [
{
program_id: 317103604,
program_description: "This animated series tells of the adventures of boy reporter Tintin, his dog, Snowy, and their friend Captain Haddock. From the stories by Herge.",
program_description_type: "Generic Description"
},
{
program_id: 317103604,
program_description: "Go on wild adventures with a boy reporter Tintin, his dog and Captain Haddock.",
program_description_type: "Generic Description"
}
]

So as per documentation if I try this :-
expect_json_types('description.*',program_id: :integer, program_description: :string, program_description_type: :string)

I must be able to validate the json types but I'm getting this error :-

Failures:

  1. api /program/:programid: should validate types and values of movie data
    Failure/Error: expect_json_types('description.*',program_id: :integer, program_description: :string, program_description_type: :string)
 Airborne::PathError:
   Expected Array
   to be an object with property description
 # /home/vj/.rvm/gems/ruby-2.1.4/gems/airborne-0.2.5/lib/airborne/path_matcher.rb:21:in `rescue in block in get_by_path'
 # /home/vj/.rvm/gems/ruby-2.1.4/gems/airborne-0.2.5/lib/airborne/path_matcher.rb:18:in `block in get_by_path'
 # /home/vj/.rvm/gems/ruby-2.1.4/gems/airborne-0.2.5/lib/airborne/path_matcher.rb:9:in `each'
 # /home/vj/.rvm/gems/ruby-2.1.4/gems/airborne-0.2.5/lib/airborne/path_matcher.rb:9:in `each_with_index'
 # /home/vj/.rvm/gems/ruby-2.1.4/gems/airborne-0.2.5/lib/airborne/path_matcher.rb:9:in `get_by_path'
 # /home/vj/.rvm/gems/ruby-2.1.4/gems/airborne-0.2.5/lib/airborne/request_expectations.rb:137:in `call_with_path'
 # /home/vj/.rvm/gems/ruby-2.1.4/gems/airborne-0.2.5/lib/airborne/request_expectations.rb:12:in `expect_json_types'
 # ./spec/program_programid_spec/api_program_programid_for_mov_happy_path_new_spec.rb:52:in `block (2 levels) in <top (required)>'
 # ------------------
 # --- Caused by: ---
 # TypeError:
 #   no implicit conversion of Symbol into Integer
 #   /home/vj/.rvm/gems/ruby-2.1.4/gems/airborne-0.2.5/lib/airborne/path_matcher.rb:57:in `[]'

Finished in 0.61998 seconds (files took 0.41055 seconds to load)
1 example, 1 failure

Please can you look into this. issue.

@sethpollack
Copy link
Collaborator

Is description a key on an object?

@sethpollack
Copy link
Collaborator

Pretty sure thats not valid JSON. It should look like:

{
    "description": [{
        "program_id": 317103604,
        "program_description": "This animated series tells of the adventures of boy reporter Tintin, his dog, Snowy, and their friend Captain Haddock. From the stories by Herge.",
        "program_description_type": "Generic Description"
    }, {
        "program_id": 317103604,
        "program_description": "Go on wild adventures with a boy reporter Tintin, his dog and Captain Haddock.",
        "program_description_type": "Generic Description"
    }]
}

@vjster
Copy link
Author

vjster commented Apr 18, 2016

Yes Seth, description is a key on a bigger object.
I just pasted a part of the json. I'm sorry for that.

And yes, what I had earlier posted was not a valid json. What you have corrected is the valid one.
Forgive me for copying the key values directly from the browser and not the raw version.

@vjster
Copy link
Author

vjster commented Apr 20, 2016

An update on this issue :-

I'm able to do schema validation for all arrays but not able to do the same for any of the arrays.

So,
expect_json_types('description.*', {program_id: :integer,program_description: :string,program_description_type: :string}) works fine.

But,
expect_json_types('description.?', {program_id: :integer,program_description: :string,program_description_type: :string}) does'nt work.

It still checks all arrays.

My Scenario: I have a json response of programs in which the majority of programs have descriptions which consist of an array of hashes, but for one particular program the description key is null.

So my test has inevitably become if any of the description key matches the following schema.

Thanks for your support once again. :)

Regards,
VJ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants