2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../../support/test-helper');
|
2017-11-14 20:46:47 +08:00
|
|
|
|
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var TestClient = require('../../support/test-client');
|
|
|
|
|
|
|
|
describe('analyses controller', function () {
|
|
|
|
const mapConfig = {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers:
|
|
|
|
[{
|
|
|
|
type: 'cartodb',
|
|
|
|
options:
|
|
|
|
{
|
|
|
|
source: { id: 'a1' },
|
|
|
|
cartocss: TestClient.CARTOCSS.POLYGONS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
dataviews: {},
|
|
|
|
analyses:
|
|
|
|
[{
|
|
|
|
id: 'a1',
|
|
|
|
type: 'buffer',
|
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from analysis_banks limit 1'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
radius: 250
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
this.testClient = new TestClient(mapConfig, 1234);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get an array of analyses from catalog', function (done) {
|
|
|
|
this.testClient.getAnalysesCatalog({}, (err, result) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.ok(Array.isArray(result.catalog));
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support jsonp responses', function (done) {
|
|
|
|
this.testClient.getAnalysesCatalog({ jsonp: 'jsonp_test' }, (err, result) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.ok(result);
|
|
|
|
|
|
|
|
let didRunJsonCallback = false;
|
|
|
|
// jshint ignore:start
|
2019-10-22 01:07:24 +08:00
|
|
|
function jsonp_test (body) {
|
2017-11-14 20:46:47 +08:00
|
|
|
assert.ok(Array.isArray(body.catalog));
|
|
|
|
didRunJsonCallback = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
eval(result);
|
|
|
|
// jshint ignore:end
|
|
|
|
|
|
|
|
assert.ok(didRunJsonCallback);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should respond "unauthorized" when missing api_key', function (done) {
|
|
|
|
const apiKey = this.testClient.apiKey;
|
|
|
|
this.testClient.apiKey = null;
|
|
|
|
|
|
|
|
this.testClient.getAnalysesCatalog({ status: 401 }, (err, result) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepEqual(result.errors[0], 'Unauthorized');
|
|
|
|
this.testClient.apiKey = apiKey;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get an array of analyses from catalog', function (done) {
|
|
|
|
this.testClient.getTile(0, 0, 0, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.testClient.getAnalysesCatalog({}, (err, result) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.ok(Array.isArray(result.catalog));
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ok(result.catalog.length >= 2); // buffer & source at least
|
2017-11-14 20:46:47 +08:00
|
|
|
|
|
|
|
result.catalog
|
|
|
|
.filter(analysis => analysis.node_id === '0a215e1f3405381cf0ea6b3b0deb6fdcfdc2fcaa')
|
2019-10-22 01:41:03 +08:00
|
|
|
.forEach(analysis => assert.strictEqual(analysis.type, 'buffer'));
|
2017-11-14 20:46:47 +08:00
|
|
|
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-11-19 20:47:07 +08:00
|
|
|
});
|