Update and add tests

This commit is contained in:
Petr Sloup 2016-03-11 11:27:17 +01:00
parent 8a46bd8b88
commit 1c73c14d84
5 changed files with 94 additions and 11 deletions

View File

@ -1,37 +1,69 @@
describe('Metadata', function() {
describe('/index.json', function() {
var testTileJSONArray = function(url) {
describe(url + ' is array of TileJSONs', function() {
it('is json', function(done) {
supertest(app)
.get('/index.json')
.get(url)
.expect(200)
.expect('Content-Type', /application\/json/, done);
});
it('is non-empty array', function(done) {
supertest(app)
.get('/index.json')
.get(url)
.expect(function(res) {
res.body.should.be.Array();
res.body.length.should.be.greaterThan(0);
}).end(done);
});
});
};
describe('/test.json', function() {
var testTileJSON = function(url, basename) {
describe(url + ' is TileJSON', function() {
it('is json', function(done) {
supertest(app)
.get('/test.json')
.get(url)
.expect(200)
.expect('Content-Type', /application\/json/, done);
});
it('has valid basename and tiles', function(done) {
supertest(app)
.get('/test.json')
.get(url)
.expect(function(res) {
res.body.basename.should.equal('test');
res.body.basename.should.equal(basename);
res.body.tiles.length.should.be.greaterThan(0);
}).end(done);
});
});
};
describe('Metadata', function() {
testTileJSONArray('/index.json');
testTileJSONArray('/raster.json');
testTileJSONArray('/vector.json');
describe('/styles.json is valid array', function() {
it('is json', function(done) {
supertest(app)
.get('/styles.json')
.expect(200)
.expect('Content-Type', /application\/json/, done);
});
it('contains valid item', function(done) {
supertest(app)
.get('/styles.json')
.expect(function(res) {
res.body.should.be.Array();
res.body.length.should.be.greaterThan(0);
res.body[0].version.should.equal(8);
res.body[0].id.should.be.String();
res.body[0].name.should.be.String();
}).end(done);
});
});
testTileJSON('/raster/test.json', 'test');
testTileJSON('/vector/zurich-vector.json', 'zurich-vector');
});

View File

@ -1,6 +1,6 @@
var testStatic = function(prefix, q, format, status, scale, type) {
if (scale) q += '@' + scale + 'x';
var path = '/' + prefix + '/static/' + q + '.' + format;
var path = '/static/' + prefix + '/' + q + '.' + format;
it(path + ' returns ' + status, function(done) {
var test = supertest(app).get(path);
if (status) test.expect(status);

49
test/style.js Normal file
View File

@ -0,0 +1,49 @@
var testIs = function(url, type, status) {
it(url + ' return ' + (status || 200) + ' and is ' + type.toString(),
function(done) {
supertest(app)
.get(url)
.expect(status || 200)
.expect('Content-Type', type, done);
});
};
describe('Styles', function() {
describe('/styles/test.json is valid style', function() {
testIs('/styles/test.json', /application\/json/);
it('contains expected properties', function(done) {
supertest(app)
.get('/styles/test.json')
.expect(function(res) {
res.body.version.should.equal(8);
res.body.name.should.be.String();
res.body.sources.should.be.Object();
res.body.glyphs.should.be.String();
res.body.sprite.should.be.String();
res.body.layers.should.be.Array();
}).end(done);
});
});
describe('/styles/streets.json is not served', function() {
testIs('/styles/streets.json', /./, 404);
});
describe('/styles/test/sprite[@2x].{format}', function() {
testIs('/styles/test/sprite.json', /application\/json/);
testIs('/styles/test/sprite@2x.json', /application\/json/);
testIs('/styles/test/sprite.png', /image\/png/);
testIs('/styles/test/sprite@2x.png', /image\/png/);
});
});
describe('Fonts', function() {
testIs('/fonts/Open Sans Bold/0-255.pbf', /application\/x-protobuf/);
testIs('/fonts/Open Sans Regular/65280-65533.pbf', /application\/x-protobuf/);
testIs('/fonts/Open Sans Bold,Open Sans Regular/0-255.pbf',
/application\/x-protobuf/);
testIs('/fonts/Nonsense,Open Sans Bold/0-255.pbf', /application\/x-protobuf/);
testIs('/fonts/Nonsense/0-255.pbf', /./, 400);
testIs('/fonts/Nonsense1,Nonsense2/0-255.pbf', /./, 400);
});

View File

@ -1,6 +1,6 @@
var testTile = function(prefix, z, x, y, format, status, scale, type) {
if (scale) y += '@' + scale + 'x';
var path = '/' + prefix + '/' + z + '/' + x + '/' + y + '.' + format;
var path = '/raster/' + prefix + '/' + z + '/' + x + '/' + y + '.' + format;
it(path + ' returns ' + status, function(done) {
var test = supertest(app).get(path);
test.expect(status);
@ -38,5 +38,7 @@ describe('Raster tiles', function() {
testTile('test', 0, 0, 0, 'png', 404, 1);
testTile('test', 0, 0, 0, 'png', 404, 4);
testTile('hybrid', 0, 0, 0, 'png', 404);
});
});

View File

@ -1,5 +1,5 @@
var testTile = function(prefix, z, x, y, status) {
var path = '/' + prefix + '/' + z + '/' + x + '/' + y + '.pbf';
var path = '/vector/' + prefix + '/' + z + '/' + x + '/' + y + '.pbf';
it(path + ' returns ' + status, function(done) {
var test = supertest(app).get(path);
if (status) test.expect(status);