-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding tests for special paging scenarios
- Loading branch information
1 parent
09bd38d
commit 0201487
Showing
4 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
var util = require('util'); | ||
var utils = require('../util/utils'); | ||
|
||
var pagingSpecial = function(optionalCoverage) { | ||
optionalCoverage['PagingSpecialNextLinkInResponseHeaders'] = 0; | ||
optionalCoverage["PagingSpecialContinuationTokenInResponseHeaders"] = 0; | ||
|
||
router.get('/nextLinkInResponseHeaders', function(req, res, next) { | ||
var headers = { | ||
'x-ms-nextLink': '/pagingSpecial/nextLinkInResponseHeaders/page/2', | ||
}; | ||
res.set(headers).status(200).json({ "value" : [ {"properties":{"id": 1, "name": "Product" }}] }); | ||
}); | ||
|
||
|
||
router.get('/nextLinkInResponseHeaders/page/:pagenumber', function(req, res, next) { | ||
if (req.params.pagenumber < 10) { | ||
var headers = { | ||
'x-ms-nextLink': '/pagingSpecial/nextLinkInResponseHeaders/page/' + (++req.params.pagenumber), | ||
}; | ||
res.set(headers).status(200).json({"value": [ {"properties":{"id" : parseInt(req.params.pagenumber), "name": "product"}} ]}); | ||
} else { | ||
optionalCoverage['PagingSpecialNextLinkInResponseHeaders'] = 0; | ||
res.status(200).json({"value": [ {"properties":{"id" : parseInt(req.params.pagenumber), "name": "product"}} ]}); | ||
} | ||
}); | ||
|
||
router.get('/continuationTokenInResponseHeaders', function(req, res, next) { | ||
|
||
if (req.headers['continuationtoken']) { | ||
contToken = req.headers['continuationtoken'] | ||
if (contToken < 10) { | ||
var headers = { | ||
'continuationtoken': ++contToken, | ||
}; | ||
res.set(headers).status(200).json({ "value" : [ {"properties":{"id": contToken, "name": "Product" }}] }); | ||
} else { | ||
res.status(200).json({"value": [ {"properties":{"id" : contToken, "name": "product"}} ]}); | ||
} | ||
|
||
} else { | ||
console.log('first') | ||
var headers = { | ||
'continuationtoken': 2, | ||
}; | ||
res.set(headers).status(200).json({ "value" : [ {"properties":{"id": 1, "name": "Product" }}] }); | ||
} | ||
|
||
}); | ||
}; | ||
|
||
pagingSpecial.prototype.router = router; | ||
|
||
module.exports = pagingSpecial; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"title": "AutoRest Special Paging Test Service", | ||
"description": "Long-running Operation for AutoRest", | ||
"version": "1.0.0" | ||
}, | ||
"host": "localhost:3000", | ||
"schemes": [ | ||
"http" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"paths": { | ||
"/pagingSpecial/nextLinkInResponseHeaders": { | ||
"get": { | ||
"x-ms-pageable": { "nextLinkName": null}, | ||
"operationId": "nextLinkInResponseHeaders", | ||
"description": "A paging operation where the next link is found in the response headers, not in the response body", | ||
"responses": { | ||
"200": { | ||
"headers": { | ||
"x-ms-nextLink": { | ||
"description": "Next link for subsequent calls", | ||
"type": "string" | ||
} | ||
}, | ||
"description": "Returns a list of products, where the next link for continued paging is located in response header x-ms-nextLink.", | ||
"schema": { | ||
"$ref": "#/definitions/ProductResultValue" | ||
} | ||
}, | ||
"default": { | ||
"description": "Unexpected error" | ||
} | ||
} | ||
} | ||
}, | ||
"/pagingSpecial/continuationTokenInResponseHeaders": { | ||
"get": { | ||
"x-ms-pageable": { "nextLinkName": null}, | ||
"operationId": "continuationTokenInResponseHeaders", | ||
"description": "A paging operation where the continuation is found in the response headers, and needs to be passed into subsequent calls.", | ||
"parameters": [ | ||
{ | ||
"name": "continuationToken", | ||
"in": "header", | ||
"type": "string", | ||
"description": "Continuation token for subsequent paging." | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"headers": { | ||
"x-ms-continuationToken": { | ||
"description": "Next link for subsequent calls", | ||
"type": "string" | ||
} | ||
}, | ||
"description": "Returns a list of products, where the next link for continued paging is located in response header x-ms-nextLink.", | ||
"schema": { | ||
"$ref": "#/definitions/ProductResultValue" | ||
} | ||
}, | ||
"default": { | ||
"description": "Unexpected error" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"ProductResultValue": { | ||
"type": "object", | ||
"properties": { | ||
"value": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/Product" | ||
} | ||
}, | ||
"nextLink": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"Product": { | ||
"type": "object", | ||
"properties": { | ||
"properties": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "integer" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |