var kanso = require('../lib/kanso'),
    dust = require('../deps/dustjs/lib/dust'),
    settings = require('../lib/settings'),
    fs = require('fs');


// integration test
exports['load'] = function (test) {
    var pdir = __dirname + '/fixtures/testproject';
    settings.load(pdir, function (err, settings) {
        test.ifError(err);
        kanso.load(pdir, settings, function (err, doc) {
            if (err) {
                throw err;
            }
            test.same(doc.settings, {
                'name': 'testproject',
                'load': 'lib/app',
                'modules': ['deps','lib'],
                'templates': 'templates',
                'attachments': 'static'
            });
            test.equals(doc.testproperty, 'test property');
            test.same(Object.keys(doc.lib).sort(), ['module1','app'].sort());
            test.equals(
                doc.lib.module1,
                fs.readFileSync(pdir + '/lib/module1.js').toString()
            );
            test.equals(
                doc.lib.app,
                fs.readFileSync(pdir + '/lib/app.js').toString()
            );
            test.same(doc.shows, {
                'testshow': 'function(){' +
                    'return require("lib/app")["shows"]["testshow"]' +
                        '.apply(this, arguments);' +
                '}'
            });
            test.same(doc.lists, {
                'testlist': 'function(){' +
                    'return require("lib/app")["lists"]["testlist"]' +
                        '.apply(this, arguments);' +
                '}'
            });
            test.same(doc.updates, {
                'testupdate': 'function(){' +
                    'return require("lib/app")["updates"]["testupdate"]' +
                        '.apply(this, arguments);' +
                '}'
            });
            test.same(doc.filters, {
                'testfilter': 'function(){' +
                    'return require("lib/app")["filters"]["testfilter"]' +
                        '.apply(this, arguments);' +
                '}'
            });
            test.equals(
                doc.validate_doc_update,
                'function(){' +
                    'return require("lib/app")["validate_doc_update"]' +
                        '.apply(this, arguments);' +
                '}'
            );
            test.same(doc.deps, {
                'module2': 'exports.name = "module two";\n'
            });
            test.equal(
                doc.no_proxy_function,
                'function (){return "test";}'
            );
            test.same(doc.no_proxy_obj, {
                fn1: 'function (){return "one";}',
                fn2: 'function (){return "two";}'
            });
            test.same(doc._attachments['static/test.txt'], {
                    'content_type': 'text/plain',
                    'data': 'dGVzdCBkYXRhCg=='
            });
            // TODO: test value of _attachments['kanso.js']
            test.same(doc.rewrites, [
                {from: '/kanso.js', to: 'kanso.js'},
                {from: '/_db/*', to: '../../*'},
                {from: '/_db', to: '../..'},
                {from: '/', to: '_show/testshow'}
            ]);
            test.done();
        });
    });
};

@@ -1185,32 +1185,40 @@
 how': 'function(
+doc, req
 )%7B' +%0A          
@@ -1220,38 +1220,98 @@
                '
-return
+var core = require(%22kanso/core%22);' +%0A                    'var fn =
  require(%22lib/ap
@@ -1334,24 +1334,21 @@
 stshow%22%5D
+;
 ' +%0A
-    
         
@@ -1360,38 +1360,48 @@
        '
-.apply(this, arguments
+return core.runShow(fn, doc, req
 );' +%0A  
@@ -1499,32 +1499,41 @@
 ist': 'function(
+head, req
 )%7B' +%0A          
@@ -1535,38 +1535,98 @@
                '
-return
+var core = require(%22kanso/core%22);' +%0A                    'var fn =
  require(%22lib/ap
@@ -1649,16 +1649,17 @@
 stlist%22%5D
+;
 ' +%0A    
@@ -1678,35 +1678,42 @@
     
-    '.apply(this, arguments
+'return core.runList(fn, head, req
 );' 
@@ -1819,32 +1819,40 @@
 ate': 'function(
+doc, req
 )%7B' +%0A          
@@ -1854,38 +1854,98 @@
                '
-return
+var core = require(%22kanso/core%22);' +%0A                    'var fn =
  require(%22lib/ap
@@ -1964,32 +1964,33 @@
 %22%5D%5B%22testupdate%22%5D
+;
 ' +%0A            
@@ -2001,36 +2001,190 @@
     
-    '.apply(this, arguments)
+'var r;' +%0A                    'core.runUpdate(fn, doc, req, function (err, res) %7B ' +%0A                        'r = res; ' +%0A                    '%7D);' +%0A                    'return r
 ;' +

update test suite for changes to wrapping of list, show and update functions #164