mattetti / Weasel-Diesel

DSL to describe, document and test web services
MIT License
438 stars 21 forks source link

Invalid JSON response #34

Open theCrab opened 10 years ago

theCrab commented 10 years ago

Hi When I run I get the Invalid JSON response. What am I doing wrong.

describe_service "v1/profiles" do |service|
  service.formats   :json
  service.http_verb :get
  service.disable_auth # on by default
   # INPUT
  service.params

   # ACTION/IMPLEMENTATION
  service.implementation do
    profiles = Profile.all
    status 200; profiles.to_json
  end
end

class ProfileSpec < MiniTest::Spec
  it "performs request" do
    TestApi.get "v1/profiles"
    assert_api_response
  end
end

# RESPONSE: surely not a JSON data response
Invalid JSON response:
[
{"id"=>1, "full_name"=>"Nelson Kelem", "avatar"=>"http://www.avatars.me", "bio"=>"What is wrong with us", "company"=>"Safarista Design", "note"=>"Kill the bagger", "type"=>"passenger", "created_at"=>"2014-01-07T22:05:10+00:00", "updated_at"=>"2014-01-07T22:05:10+00:00"}, 
{"id"=>2, "full_name"=>"Joe Di Panto", "avatar"=>"http://www.avatars.me", "bio"=>"What is wrong with us", "company"=>"Safarista Design", "note"=>"Shoot the bagger", "type"=>"passenger", "created_at"=>"2014-01-07T22:05:10+00:00", "updated_at"=>"2014-01-07T22:05:10+00:00"}
]

I am expecting the response to be this or similar JSON. What is happened here.

"profiles":[
{"id":1,"full_name":"Joe Di Panto","avatar":"http://www.avatars.me","bio":"What is wrong with us","company":"Safarista Design","note":"Shoot the bagger","type":"passenger","created_at":"2014-01-08T16:14:25+00:00","updated_at":"2014-01-08T16:14:25+00:00"},
{"id":2,"full_name":"Joe Di Panto","avatar":"http://www.avatars.me","bio":"What is wrong with us","company":"Safarista Design","note":"Shoot the bagger","type":"passenger","created_at":"2014-01-08T16:14:25+00:00","updated_at":"2014-01-08T16:14:25+00:00"}
]
theCrab commented 10 years ago

@mattetti after looking at your example, I see what's messing my object.

Any tips on how the INPUT service.params section of a json_list service looks like? Ex. below

describe_service "/json_list" do |service|
      service.formats  :json
      service.response do |response|
        response.array :people do |node|
          node.integer :id
          node.boolean :online
          node.datetime :created_at
          node.object :team do |team|
            team.integer :id
            team.float :score, :null => true
          end
        end
      end
    end