Commit 261793cf authored by Adrien Pavie's avatar Adrien Pavie
Browse files

Tests for search routes

parent 50ecc78c
......@@ -34,8 +34,8 @@ exports.default = function(req, res) {
* @apiParam {Number} lat The latitude (WGS84)
* @apiParam {Number} lng The longitude (WGS84)
* @apiParam {Number} radius The radius around the point, in meters
* @apiParam {Long} [mindate] The minimum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)
* @apiParam {Long} [maxdate] The maximum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)
* @apiParam {Long} [mindate] The minimum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)
* @apiParam {Long} [maxdate] The maximum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)
* @apiParam {String} [use] The list of fetchers to use (comma-separated)
* @apiParam {String} [ignore] The list of fetchers to ignore (comma-separated)
*
......@@ -43,13 +43,13 @@ exports.default = function(req, res) {
* @apiSuccess {Array} pictures The retrieved pictures, see <a href="https://framagit.org/PanierAvide/Pic4Carto.js/blob/master/doc/API.md#picture">details about the Picture object</a>.
*/
exports.searchAround = function(req, res) {
console.log("[SEARCH] "
/*console.log("[SEARCH] "
+req.query.radius
+" meters around "
+req.query.lat+", "+req.query.lng
+" between TS "
+req.query.mindate+" and "+req.query.maxdate
+" (use "+req.query.use+" | ignore "+req.query.ignore+")");
+" (use "+req.query.use+" | ignore "+req.query.ignore+")");*/
const picManager = new P4C.PicturesManager({ fetcherCredentials: CREDENTIALS });
......@@ -68,15 +68,15 @@ exports.searchAround = function(req, res) {
new P4C.LatLng(req.query.lat, req.query.lng),
req.query.radius,
{
mindate: req.query.mindate,
maxdate: req.query.maxdate,
mindate: req.query.mindate ? parseInt(req.query.mindate) : undefined,
maxdate: req.query.maxdate ? parseInt(req.query.maxdate) : undefined,
usefetchers: req.query.use ? req.query.use.split(',') : undefined,
ignorefetchers: req.query.ignore ? req.query.ignore.split(',') : undefined
}
);
}
catch(e) {
res.status(500).send({ "status": "NOTOK", "error": e });
res.status(500).send({ "status": "NOTOK", "error": e.toString() });
}
};
......@@ -90,8 +90,8 @@ exports.searchAround = function(req, res) {
* @apiParam {Number} west The minimal longitude (WGS84)
* @apiParam {Number} north The maximal latitude (WGS84)
* @apiParam {Number} east The maximal longitude (WGS84)
* @apiParam {Long} [mindate] The minimum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)
* @apiParam {Long} [maxdate] The maximum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)
* @apiParam {Long} [mindate] The minimum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)
* @apiParam {Long} [maxdate] The maximum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)
* @apiParam {String} [use] The list of fetchers to use (comma-separated)
* @apiParam {String} [ignore] The list of fetchers to ignore (comma-separated)
*
......@@ -99,11 +99,11 @@ exports.searchAround = function(req, res) {
* @apiSuccess {Array} pictures The retrieved pictures, see <a href="https://framagit.org/PanierAvide/Pic4Carto.js/blob/master/doc/API.md#picture">details about the Picture object</a>.
*/
exports.searchBbox = function(req, res) {
console.log("[SEARCH] BBox "
/*console.log("[SEARCH] BBox "
+req.query.south+", "+req.query.west+", "+req.query.north+", "+req.query.east
+" between TS "
+req.query.mindate+" and "+req.query.maxdate
+" (use "+req.query.use+" | ignore "+req.query.ignore+")");
+" (use "+req.query.use+" | ignore "+req.query.ignore+")");*/
const picManager = new P4C.PicturesManager({ fetcherCredentials: CREDENTIALS });
......@@ -121,15 +121,15 @@ exports.searchBbox = function(req, res) {
picManager.startPicsRetrieval(
new P4C.LatLngBounds(new P4C.LatLng(req.query.south, req.query.west), new P4C.LatLng(req.query.north, req.query.east)),
{
mindate: req.query.mindate,
maxdate: req.query.maxdate,
mindate: req.query.mindate ? parseInt(req.query.mindate) : undefined,
maxdate: req.query.maxdate ? parseInt(req.query.maxdate) : undefined,
usefetchers: req.query.use ? req.query.use.split(',') : undefined,
ignorefetchers: req.query.ignore ? req.query.ignore.split(',') : undefined
}
);
}
catch(e) {
res.status(500).send({ "status": "NOTOK", "error": e });
res.status(500).send({ "status": "NOTOK", "error": e.toString() });
}
};
......
......@@ -66,14 +66,14 @@ define({ "api": [
"type": "Long",
"optional": true,
"field": "mindate",
"description": "<p>The minimum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)</p>"
"description": "<p>The minimum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)</p>"
},
{
"group": "Parameter",
"type": "Long",
"optional": true,
"field": "maxdate",
"description": "<p>The maximum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)</p>"
"description": "<p>The maximum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)</p>"
},
{
"group": "Parameter",
......@@ -159,14 +159,14 @@ define({ "api": [
"type": "Long",
"optional": true,
"field": "mindate",
"description": "<p>The minimum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)</p>"
"description": "<p>The minimum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)</p>"
},
{
"group": "Parameter",
"type": "Long",
"optional": true,
"field": "maxdate",
"description": "<p>The maximum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)</p>"
"description": "<p>The maximum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)</p>"
},
{
"group": "Parameter",
......
......@@ -66,14 +66,14 @@
"type": "Long",
"optional": true,
"field": "mindate",
"description": "<p>The minimum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)</p>"
"description": "<p>The minimum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)</p>"
},
{
"group": "Parameter",
"type": "Long",
"optional": true,
"field": "maxdate",
"description": "<p>The maximum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)</p>"
"description": "<p>The maximum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)</p>"
},
{
"group": "Parameter",
......@@ -159,14 +159,14 @@
"type": "Long",
"optional": true,
"field": "mindate",
"description": "<p>The minimum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)</p>"
"description": "<p>The minimum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)</p>"
},
{
"group": "Parameter",
"type": "Long",
"optional": true,
"field": "maxdate",
"description": "<p>The maximum timestamp for a given time range, in seconds since 1st january 1970 (Epoch)</p>"
"description": "<p>The maximum timestamp for a given time range, in milliseconds since 1st january 1970 (Epoch)</p>"
},
{
"group": "Parameter",
......
......@@ -8,7 +8,7 @@ define({
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2017-06-11T10:53:01.435Z",
"time": "2017-06-15T10:31:52.352Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
......
......@@ -8,7 +8,7 @@
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2017-06-11T10:53:01.435Z",
"time": "2017-06-15T10:31:52.352Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
......
......@@ -70,9 +70,87 @@ describe('Server routes', function() {
});
});
//TODO Test with minimal parameters
it("should return pictures on GET with BBox only", function(done){
request(server)
.get("/search/bbox?south=48.125&north=48.13&west=-1.69&east=-1.685")
.expect("Content-type",/json/)
.expect(200)
.end(function(err, res){
assert.equal(res.status, 200);
assert.equal(res.body.status, "OK");
assert.ok(res.body.pictures.length > 0);
assert.ok(res.body.pictures[0].pictureUrl.startsWith("http"));
assert.ok(res.body.pictures[0].date > 0);
assert.ok(res.body.pictures[0].coordinates !== undefined);
assert.ok(res.body.pictures[0].provider !== undefined);
assert.ok(res.body.pictures[0].author !== undefined);
assert.ok(res.body.pictures[0].license !== undefined);
assert.ok(res.body.pictures[0].detailsUrl.startsWith("http"));
done();
});
}).timeout(15000);
//TODO Test with all parameters
it("should return pictures on GET with BBox and time range defined", function(done){
request(server)
.get("/search/bbox?south=48.125&north=48.13&west=-1.69&east=-1.685&mindate=1495324800000&maxdate=1495411200000")
.expect("Content-type",/json/)
.expect(200)
.end(function(err, res){
assert.equal(res.status, 200);
assert.equal(res.body.status, "OK");
assert.equal(res.body.pictures.length, 31);
assert.equal(res.body.pictures[0].pictureUrl, "https://d1cuyjsrcm0gby.cloudfront.net/eJMBmO6ndsHysDHsSHdhuQ/thumb-2048.jpg");
assert.ok(res.body.pictures[0].date > 0);
assert.ok(res.body.pictures[0].coordinates !== undefined);
assert.equal(res.body.pictures[0].provider, "Mapillary");
assert.equal(res.body.pictures[0].author, "panieravide");
assert.equal(res.body.pictures[0].license, "CC By-SA 4.0");
assert.equal(res.body.pictures[0].detailsUrl, "https://www.mapillary.com/app/?pKey=eJMBmO6ndsHysDHsSHdhuQ&lat=48.127471560000004&lng=-1.6850350500000104&focus=photo");
done();
});
}).timeout(15000);
it("should return no pictures on GET with BBox, time range and use defined over Rennes", function(done){
request(server)
.get("/search/bbox?south=48.125&north=48.13&west=-1.69&east=-1.685&mindate=1495324800000&maxdate=1495411200000&use=openstreetcam,wikicommons")
.expect("Content-type",/json/)
.expect(200)
.end(function(err, res){
assert.equal(res.status, 200);
assert.equal(res.body.status, "OK");
assert.equal(res.body.pictures.length, 0);
done();
});
}).timeout(15000);
it("should return no pictures on GET with BBox, time range and ignore defined over Rennes", function(done){
request(server)
.get("/search/bbox?south=48.125&north=48.13&west=-1.69&east=-1.685&mindate=1495324800000&maxdate=1495411200000&ignore=mapillary")
.expect("Content-type",/json/)
.expect(200)
.end(function(err, res){
assert.equal(res.status, 200);
assert.equal(res.body.status, "OK");
assert.equal(res.body.pictures.length, 0);
done();
});
}).timeout(15000);
it("should return filtered pictures on GET with BBox, time range and use defined over SF", function(done){
request(server)
.get("/search/bbox?south=37.77&north=37.775&west=-122.455&east=-122.45&mindate=1491091200000&maxdate=1491177600000&use=openstreetcam")
.expect("Content-type",/json/)
.expect(200)
.end(function(err, res){
assert.equal(res.status, 200);
assert.equal(res.body.status, "OK");
assert.equal(res.body.pictures.length, 20);
for(const p of res.body.pictures) {
assert.equal(p.provider, "OpenStreetCam");
}
done();
});
}).timeout(15000);
});
describe('/search/around', function() {
......@@ -88,7 +166,25 @@ describe('Server routes', function() {
});
});
//TODO Test with minimal parameters
it("should return pictures on GET with coordinates + radius only", function(done){
request(server)
.get("/search/around?lat=48.125&lng=-1.69&radius=500")
.expect("Content-type",/json/)
.expect(200)
.end(function(err, res){
assert.equal(res.status, 200);
assert.equal(res.body.status, "OK");
assert.ok(res.body.pictures.length > 0);
assert.ok(res.body.pictures[0].pictureUrl.startsWith("http"));
assert.ok(res.body.pictures[0].date > 0);
assert.ok(res.body.pictures[0].coordinates !== undefined);
assert.ok(res.body.pictures[0].provider !== undefined);
assert.ok(res.body.pictures[0].author !== undefined);
assert.ok(res.body.pictures[0].license !== undefined);
assert.ok(res.body.pictures[0].detailsUrl.startsWith("http"));
done();
});
}).timeout(15000);
//TODO Test with all parameters
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment