Permalink
Browse files

Add endpoint tests.

  • Loading branch information...
1 parent c1ce714 commit 0b34b4acb8da7a20bbf10cc798a866768f75425f Will White committed Jan 13, 2011
Showing with 171 additions and 0 deletions.
  1. +23 −0 test/fixtures/project1.json
  2. +40 −0 test/fixtures/project2.json
  3. +106 −0 test/tilelive.test.js
  4. +2 −0 tests.sh
@@ -0,0 +1,23 @@
+{
+ "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs",
+ "Stylesheet": [
+ {
+ "id": "style.mss",
+ "data": "#world { polygon-fill: #eee; line-color: #ccc; line-width: 0.5;}"
+ }
+ ],
+ "Layer": [
+ {
+ "id": "world",
+ "name": "world",
+ "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs",
+ "Datasource": {
+ "file": "http://tilemill-data.s3.amazonaws.com/world_borders_merc.zip",
+ "type": "shape",
+ "estimate_extent": "true",
+ "id": "world"
+ }
+ }
+ ],
+ "id": "Test"
+}
@@ -0,0 +1,40 @@
+{
+ "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs",
+ "Stylesheet": [
+ {
+ "id": "style.mss",
+ "data": "#world { polygon-fill: #eee; line-color: #ccc; line-width: 0.5;}"
+ }
+ ],
+ "Layer": [
+ {
+ "id": "world",
+ "name": "world",
+ "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs",
+ "Datasource": {
+ "file": "http://tilemill-data.s3.amazonaws.com/world_borders_merc.zip",
+ "type": "shape",
+ "estimate_extent": "true",
+ "id": "world"
+ }
+ },
+ {
+ "id": "glaciated",
+ "name": "glaciated",
+ "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs",
+ "class": "",
+ "Datasource": {
+ "file": "http://tilemill-data.s3.amazonaws.com/natural-earth/10m_glaciated_areas_900913.zip",
+ "type": "shape",
+ "estimate_extent": "id",
+ "id": "glaciated"
+ }
+ }
+ ],
+ "id": "Test",
+ "center": {
+ "lat": 0,
+ "lon": 0,
+ "zoom": 2
+ }
+}
View
@@ -0,0 +1,106 @@
+require.paths.unshift(__dirname + '/../lib/node', __dirname + '/../');
+var assert = require('assert');
+var fs = require('fs');
+
+var app = require('tilemill');
+var inspect = require('inspect');
+
+var project = '';
+var project2 = '';
+module.exports = {
+ 'abilities': function() {
+ assert.response(app, { url: '/abilities' }, {
+ status: 200
+ }, function(res) {
+ var data = JSON.parse(res.body);
+ assert.ok(data.fonts, 'Available fonts');
+ assert.ok(data.datasources, 'Available datasources');
+ });
+ },
+ 'version': function() {
+ assert.response(app, {
+ url: '/api',
+ }, {
+ status: 200
+ }, function(res) {
+ var data = JSON.parse(res.body);
+ assert.equal(data.api, 'basic', 'API');
+ assert.equal(data.version, 1, 'API Version');
+ });
+ },
+ 'create project': function() {
+ fs.readFile('./test/fixtures/project1.json', 'utf8', function(err, project) {
+ assert.response(app, {
+ url: '/api/project/Test',
+ method: 'PUT',
+ headers: {
+ 'content-type': 'application/json'
+ },
+ data: project
+ }, {
+ status: 200
+ }, function(res) {
+ assert.equal(JSON.stringify(JSON.parse(res.body)), JSON.stringify(JSON.parse(project)));
+ });
+ });
+ },
+ 'load project': function() {
+ fs.readFile('./test/fixtures/project1.json', 'utf8', function(err, project) {
+ assert.response(app, {
+ url: '/api/project/Test',
+ method: 'GET',
+ }, {
+ status: 200
+ }, function(res) {
+ assert.equal(JSON.stringify(JSON.parse(res.body)), JSON.stringify(JSON.parse(project)));
+ });
+ });
+ },
+ 'edit project': function() {
+ fs.readFile('./test/fixtures/project2.json', 'utf8', function(err, project) {
+ assert.response(app, {
+ url: '/api/project/Test',
+ method: 'PUT',
+ headers: {
+ 'content-type': 'application/json'
+ },
+ data: project
+ }, {
+ status: 200
+ }, function(res) {
+ assert.equal(JSON.stringify(JSON.parse(res.body)), JSON.stringify(JSON.parse(project)));
+ });
+ });
+ },
+ 'load layer': function() {
+ assert.response(app, {url: '/aHR0cDovL2xvY2FsaG9zdDo4ODg5L2FwaS9wcm9qZWN0L1Rlc3Q_MDI3N2M0/world'}, {
+ status: 200
+ }, function(res) {
+ var data = JSON.parse(res.body);
+ assert.equal(data.id, 'world', 'Unexpected layer id');
+ assert.equal(data.features.length, 245, 'Feature count mismatch');
+ });
+ },
+ 'delete project': function() {
+ assert.response(app, {
+ url: '/api/project/Test',
+ method: 'DELETE'
+ }, {
+ status: 200
+ }, function(res) {
+ assert.equal(res.body, '{}');
+ });
+ },
+ 'invalid map': function() {
+ assert.response(app, { url: '/foobar' }, {
+ status: 500
+ }, function(res) {
+ var data = JSON.parse(res.body);
+ assert.equal(data.message, 'Error loading map file', 'Unexpected error message');
+ });
+ }
+};
+
+var loadFixture = function(file, callback) {
+ require('fs').readfile('./test/fixtures/' + file, callback);
+}
View
@@ -0,0 +1,2 @@
+# Help script for running tests
+NODE_ENV=test ./bin/expresso --port 8889 $*

0 comments on commit 0b34b4a

Please sign in to comment.