Commit 50ecc78c authored by Adrien Pavie's avatar Adrien Pavie
Browse files

Started writing of tests (see #3)

parent bdc6a836
......@@ -6,7 +6,7 @@
"scripts": {
"start": "nodemon server.js",
"doc": "apidoc -i api/ -o doc/",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha"
},
"repository": {
"type": "git",
......@@ -26,7 +26,9 @@
"license": "SEE LICENSE IN LICENSE.txt",
"devDependencies": {
"apidoc": "^0.17.6",
"nodemon": "^1.11.0"
"mocha": "^3.4.2",
"nodemon": "^1.11.0",
"supertest": "^3.0.0"
},
"dependencies": {
"body-parser": "^1.17.2",
......@@ -37,5 +39,5 @@
},
"apidoc": {
"title": "Pic4Carto API Documentation"
}
}
}
......@@ -32,10 +32,12 @@ app.use('/doc', express.static('doc'));
const routes = require('./api/routes/P4CaaSRoutes');
routes(app);
app.listen(port);
const server = app.listen(port);
app.use(function(req, res) {
res.status(404).send({url: req.originalUrl + ' not found'})
});
console.log('P4CaaS API started on port: ' + port);
module.exports = server;
/*
* This file is part of P4CaaS.
*
* P4CaaS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* P4CaaS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with P4CaaS. If not, see <http://www.gnu.org/licenses/>.
*/
var assert = require('assert');
var request = require('supertest');
describe('Server routes', function() {
var server;
beforeEach(function () {
delete require.cache[require.resolve('../server')];
server = require('../server');
});
afterEach(function (done) {
server.close(done);
});
describe('/', function() {
it("should return status on GET", function(done){
request(server)
.get("/")
.expect("Content-type",/json/)
.expect(200)
.end(function(err, res){
assert.equal(res.status, 200);
assert.equal(res.body.status, "OK");
done();
});
});
});
describe('/search', function() {
it("should return status on GET", function(done){
request(server)
.get("/search")
.expect("Content-type",/json/)
.expect(200)
.end(function(err, res){
assert.equal(res.status, 200);
assert.equal(res.body.status, "OK");
done();
});
});
});
describe('/search/bbox', function() {
it("should return NOTOK on GET without parameters", function(done){
request(server)
.get("/search/bbox")
.expect("Content-type",/json/)
.expect(500)
.end(function(err, res){
assert.equal(res.status, 500);
assert.equal(res.body.status, "NOTOK");
done();
});
});
//TODO Test with minimal parameters
//TODO Test with all parameters
});
describe('/search/around', function() {
it("should return NOTOK on GET without parameters", function(done){
request(server)
.get("/search/around")
.expect("Content-type",/json/)
.expect(500)
.end(function(err, res){
assert.equal(res.status, 500);
assert.equal(res.body.status, "NOTOK");
done();
});
});
//TODO Test with minimal parameters
//TODO Test with all parameters
});
describe('/fetchers', function() {
it("should return fetchers on GET", function(done){
request(server)
.get("/fetchers")
.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.fetchers.mapillary.name, "Mapillary");
assert.equal(res.body.fetchers.mapillary.homepageUrl, "https://www.mapillary.com/");
done();
});
});
});
});
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