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');
        });
    },
    'project manipulation': 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)));
            });
            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)));
            });
            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)));
            });
            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');
            });
            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);
}

@@ -1439,32 +1439,59 @@
             %7D);%0A
+            // Get project%0A
             asse
@@ -1501,32 +1501,32 @@
 response(app, %7B%0A
-
                 
@@ -1771,32 +1771,161 @@
             %7D);%0A
+%0A            fs.readFile('./test/fixtures/project2.json', 'utf8', function(err, project) %7B%0A                // Update project%0A    
             asse
@@ -1935,32 +1935,36 @@
 response(app, %7B%0A
+    
                 
@@ -1997,32 +1997,36 @@
                 
+    
 method: 'PUT',%0A 
@@ -2032,32 +2032,36 @@
                 
+ 
+   
 headers: %7B%0A     
@@ -2047,32 +2047,36 @@
      headers: %7B%0A
+    
                 
@@ -2122,35 +2122,43 @@
                 
-%7D,%0A
+    %7D,%0A    
                 
@@ -2163,32 +2163,36 @@
   data: project%0A
+    
             %7D, %7B
@@ -2200,32 +2200,36 @@
                 
+    
 status: 200%0A    
@@ -2216,32 +2216,36 @@
     status: 200%0A
+    
             %7D, f
@@ -2251,32 +2251,36 @@
 function(res) %7B%0A
+    
                 
@@ -2372,36 +2372,74 @@
 ));%0A            
+    
 %7D);%0A
+                // Load layer%0A    
             asse
@@ -2543,32 +2543,36 @@
                 
+    
 status: 200%0A    
@@ -2559,32 +2559,36 @@
     status: 200%0A
+    
             %7D, f
@@ -2610,32 +2610,36 @@
                 
+ 
+   
 var data = JSON.
@@ -2647,32 +2647,36 @@
 arse(res.body);%0A
+    
                 
@@ -2738,32 +2738,36 @@
                 
+   
+ 
 assert.equal(dat
@@ -2821,36 +2821,78 @@
 ');%0A            
-%7D);%0A
+    %7D);%0A                // Delete project%0A    
             asse
@@ -2902,32 +2902,36 @@
 response(app, %7B%0A
+    
                 
@@ -2964,32 +2964,36 @@
                 
+ 
+   
 method: 'DELETE'
@@ -2997,32 +2997,36 @@
 TE'%0A            
+    
 %7D, %7B%0A           
@@ -3022,32 +3022,36 @@
                 
+   
+ 
 status: 200%0A    
@@ -3038,32 +3038,36 @@
     status: 200%0A
+    
             %7D, f
@@ -3089,32 +3089,36 @@
                 
+    
 assert.equal(res
@@ -3127,24 +3127,44 @@
 ody, '%7B%7D');%0A
+                %7D);%0A
             

Add comments to test.