Fix API not returning anything if bad URL
This commit is contained in:
@@ -88,14 +88,18 @@ var ApiController = function(app) {
|
||||
.fail(function(err) {
|
||||
debug('Saving results to resultsDatastore failed:');
|
||||
debug(err);
|
||||
|
||||
res.status(500).send('Saving results failed');
|
||||
});
|
||||
|
||||
}).fail(function(err) {
|
||||
|
||||
console.error('Test failed for %s', run.params.url);
|
||||
console.error('Test failed for URL: %s', run.params.url);
|
||||
console.error(err.toString());
|
||||
|
||||
runsDatastore.markAsFailed(run.runId, err.toString());
|
||||
|
||||
res.status(400).send('Bad request');
|
||||
|
||||
}).finally(function() {
|
||||
queue.remove(run.runId);
|
||||
|
||||
@@ -41,6 +41,50 @@ describe('api', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail without an URL when asynchronous', function(done) {
|
||||
this.timeout(15000);
|
||||
|
||||
request({
|
||||
method: 'POST',
|
||||
url: serverUrl + '/api/runs',
|
||||
body: {
|
||||
url: ''
|
||||
},
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Api-Key': Object.keys(config.authorizedKeys)[0]
|
||||
}
|
||||
}, function(error, response, body) {
|
||||
if (!error && response.statusCode === 400) {
|
||||
done();
|
||||
} else {
|
||||
done(error || response.statusCode);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail without an URL when synchronous', function(done) {
|
||||
this.timeout(15000);
|
||||
|
||||
request({
|
||||
method: 'POST',
|
||||
url: serverUrl + '/api/runs',
|
||||
body: {
|
||||
url: '',
|
||||
waitForResponse: true
|
||||
},
|
||||
json: true,
|
||||
headers: {
|
||||
'X-Api-Key': Object.keys(config.authorizedKeys)[0]
|
||||
}
|
||||
}, function(error, response, body) {
|
||||
if (!error && response.statusCode === 400) {
|
||||
done();
|
||||
} else {
|
||||
done(error || response.statusCode);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should launch a synchronous run', function(done) {
|
||||
this.timeout(15000);
|
||||
|
||||
Reference in New Issue
Block a user