Skip to content

Commit

Permalink
UNit test for parameter override at operation level subeeshcbabu-zz#25
Browse files Browse the repository at this point in the history
  • Loading branch information
subeeshcbabu committed Sep 9, 2016
1 parent c6e9da4 commit efcc692
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
26 changes: 11 additions & 15 deletions tests/fixture/petstore.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@
}
},
"/pet/{petId}": {
"parameters": [{
"name": "petId",
"in": "path",
"description": "ID of pet to return",
"required": true,
"type": "integer",
"format": "int64"
}],
"get": {
"tags": ["pet"],
"summary": "Find pet by ID",
Expand All @@ -184,6 +192,8 @@
"description": "ID of pet to return",
"required": true,
"type": "integer",
"minimum": 1000,
"maximum": 2000,
"format": "int64"
},
{
Expand Down Expand Up @@ -219,14 +229,7 @@
"operationId": "updatePetWithForm",
"consumes": ["application/x-www-form-urlencoded"],
"produces": ["application/xml", "application/json"],
"parameters": [{
"name": "petId",
"in": "path",
"description": "ID of pet that needs to be updated",
"required": true,
"type": "integer",
"format": "int64"
}, {
"parameters": [ {
"name": "name",
"in": "formData",
"description": "Updated name of the pet",
Expand Down Expand Up @@ -259,13 +262,6 @@
"in": "header",
"required": false,
"type": "string"
}, {
"name": "petId",
"in": "path",
"description": "Pet id to delete",
"required": true,
"type": "integer",
"format": "int64"
}],
"responses": {
"400": {
Expand Down
21 changes: 20 additions & 1 deletion tests/param_mockgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,33 @@ describe('Parameter Mock generator', function () {
Assert.ok(params.path, 'Generated path parameter');
Assert.ok(params.path[0].name === 'petId', 'generated mock parameter for petId');
Assert.ok(Number.isInteger(params.path[0].value), 'OK value for petId');

//Test the operation level overrides
Assert.ok(params.path[0].value > 1000 && params.path[0].value < 2000, 'OK value for petId');

Assert.ok(params.query, 'Generated query parameter');
Assert.ok(params.query[0].name === 'petName', 'generated mock parameter for petName');
Assert.ok(/awesome+ (pet|cat|bird)/.test(params.query[0].value), 'OK value for petName');
done();
});
});

it('should generate parameter mock for path /pet/{petId} post - common parameter', function(done) {
swagmock.parameters({
path: '/pet/{petId}',
operation: 'post'
}, function(err, mock) {
Assert.ok(!err, 'No error');
Assert.ok(mock, 'Generated mock');
var params = mock.parameters;
Assert.ok(params, 'Generated parameters');
Assert.ok(params.path, 'Generated path parameter');
Assert.ok(params.path[0].name === 'petId', 'generated mock parameter for petId');
Assert.ok(Number.isInteger(params.path[0].value), 'OK value for petId');

done();
});
});

it('should generate parameter mock for path /pet/{petId}/uploadImage', function(done) {
swagmock.parameters({
path: '/pet/{petId}/uploadImage',
Expand Down

0 comments on commit efcc692

Please sign in to comment.