<https://lh3.googleusercontent.com/-KdyS1bGV7uI/WH8uvIe5lRI/AAAAAAAAAAM/TpGsmO6o8XARExX_fUeIAMODm7dPIga8gCLcB/s1600/console.png>

I have modified example spec (refer http://editor.swagger.io/#/ 
<https://github.com/earldouglas/swagger-test/issues/url> example- 
heroku-pets) and i am trying to test this spec using swagger-test. But i am 
stuck at one point,

*AssertionError: expected { Object (description, request, ...) } to deeply 
equal { Object (description, request, ...) }*

What i think the reason is, i am not correctly mentioning the uri for get/ in 
tests.js file. Actually the uri should be- 
*http://petstore-api.herokuapp.com/pet/?limit=11 
<http://petstore-api.herokuapp.com/pet/?limit=11>* and what my code is 
taking is *http://petstore-api.herokuapp.com/pet/ 
<http://petstore-api.herokuapp.com/pet/>* .
My question is,How to pass input parameters(i.e. ?limit=11) in the uri in 
tests.js? And if i am wrong, then how to resolve this issue ?


Below is the code for my swagger.json file:


{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "PetStore on Heroku",
        "description": "**This example has a working backend hosted in 
Heroku**\n\nYou can try all HTTP operation described in this Swagger 
spec.\n\nFind source code of this API 
[here](https://github.com/mohsen1/petstore-api)\n"
    },
    "host": "petstore-api.herokuapp.com",
    "basePath": "/pet",
    "schemes": [
        "http",
        "https"
    ],
    "consumes": [
        "application/json",
        "text/xml"
    ],
    "produces": [
        "application/json",
        "text/html"
    ],
    "paths": {
        "/": {
            "get": {
                "parameters": [
                    {
                        "name": "limit",
                        "in": "query",
                        "description": "number of pets to return",
                        "type": "integer",
                        "default": 11,
                        "minimum": 11,
                        "maximum": 10000
                    }
                ],
                "responses": {
                    "200": {
                        "description": "List all pets",
                        "schema": {
                            "title": "Pets",
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Pet"
                            }
                        }
                    }
                }
            }
        },
        "/{petId}": {
            "get": {
                "parameters": [
                    {
                        "name": "petId",
                        "in": "path",
                        "type": "string",
                        "description": "ID of the pet",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Sends the pet with pet Id"
                    }
                },
                "x-amples": [
                    {
                        "description": "get /{petId}: returns 200 for 
560eea43a62de703006d2b57",
                        "request": {
                            "params": {
                                "petId": "560eea43a62de703006d2b57"
                            }
                        },
                        "response": {
                            "status": 200,
                            "headers": {
                                "content-type": "application/json"
                            }
                        }
                    },
                    {
                        "request": {
                            "params": {
                                "petId": "560eea59a62de703006d2b58"
                            }
                        },
                        "response": {
                            "status": 200,
                            "headers": {
                                "content-type": "application/json"
                            }
                        }
                    }
                ]
            }
        }
    },
    "definitions": {
        "Pet": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string"
                },
                "birthday": {
                    "type": "integer",
                    "format": "int32"
                }
            }
        }
    }
}


And below is the code for my tests.js file:


'use strict';

/* global describe, it, before, beforeEach, after, afterEach */

var fs = require('fs');
var swaggerTest = require('../lib/swagger-test');
var assert = require('chai').assert;

describe('test generation with inference', function () {

  var testDir = __dirname;
  var buffer  = fs.readFileSync(testDir + '/swagger.json');
  var spec    = JSON.parse(buffer);

  var xamples = swaggerTest.parse(spec, { inferXamples: true });

  it('should contain three test cases', function () {
    assert.equal(xamples.length, 3);
  });
  var str= xamples[0].toString();
  //console.log("str: "+str);
  //console.log("xamples: "+xamples);

  it('should first test GET /', function () {
      assert.deepEqual(xamples[0], {
          "description": "get /",
          "request": {
              "method": "get",
              "uri": "petstore-api.herokuapp.com/pet/"
          },
          "response": {
              "status": 200,
              "headers": {
                  "content-type": "application/json"
              }
          }
      });
  });


  it ('should next test GET /560eea43a62de703006d2b57', function () {
      assert.deepEqual(xamples[1], {
          "description": "get /{petId}: returns 200 for 
560eea43a62de703006d2b57",
          "request": {
              "params": {
                  "petId": "560eea43a62de703006d2b57"
              },
              "method": "get",
              "uri": 
"petstore-api.herokuapp.com/pet/560eea43a62de703006d2b57"
          },
          "response": {
              "status": 200,
              "headers": {
                  "content-type": "application/json"
              }
          }
      });
  });


  it ('should next test GET /560eea59a62de703006d2b58', function () {
      assert.deepEqual(xamples[2], {
        "description": "get /{petId}",
        "request": {
            "params": {
                "petId": "560eea59a62de703006d2b58"
            },
            "method": "get",
            "uri": "petstore-api.herokuapp.com/pet/560eea59a62de703006d2b58"
        },
        "response": {
            "status": 200,
            "headers": {
                "content-type": "application/json"
            }
        }
      });
  });
});


And here is what my console is saying:


<https://lh3.googleusercontent.com/-KdyS1bGV7uI/WH8uvIe5lRI/AAAAAAAAAAM/TpGsmO6o8XARExX_fUeIAMODm7dPIga8gCLcB/s1600/console.png>





How to resolve this error? And *how to pass input parameters *like this one 
"?limit=11".






-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to swagger-swaggersocket+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to