diff --git a/test/metadata.js b/test/metadata.js index c7137d8..ffe56b8 100644 --- a/test/metadata.js +++ b/test/metadata.js @@ -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'); }); diff --git a/test/static.js b/test/static.js index ad653fe..f04121e 100644 --- a/test/static.js +++ b/test/static.js @@ -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); diff --git a/test/style.js b/test/style.js new file mode 100644 index 0000000..94990fa --- /dev/null +++ b/test/style.js @@ -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); +}); diff --git a/test/tiles_raster.js b/test/tiles_raster.js index 3d2ea1c..6ec1b2a 100644 --- a/test/tiles_raster.js +++ b/test/tiles_raster.js @@ -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); }); }); diff --git a/test/tiles_vector.js b/test/tiles_vector.js index b4e8c1a..58d11ff 100644 --- a/test/tiles_vector.js +++ b/test/tiles_vector.js @@ -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);