var assert = require('assert'),
    MongoUnit = require('mongo-unit'),
    mongo_uri;

// Make sure janeway doesn't start
process.env.DISABLE_JANEWAY = 1;

// Make MongoUnit a global
global.MongoUnit = MongoUnit;

// Require alchemymvc
require('../index.js');

describe('require(\'alchemymvc\')', function() {
	it('should create the global alchemy object', function() {
		assert.equal('object', typeof alchemy);
	});
});

describe('Mongo-unit setup', function() {
	this.timeout(70000)

	it('should create in-memory mongodb instance first', async function() {

		var url = await MongoUnit.start();

		mongo_uri = url;

		if (!url) {
			throw new Error('Failed to create mongo-unit instance');
		}
	});
});

describe('Alchemy', function() {

	describe('#start(callback)', function() {
		it('should start the server', function(done) {
			alchemy.start({silent: true}, function started() {
				done();
			});

			// Also create the mongodb datasource
			Datasource.create('mongo', 'default', {uri: mongo_uri});
		});
	});

	describe('#pathResolve(...path_to_dirs)', function() {
		it('resolves all arguments to a directory', function() {
			assert.strictEqual(alchemy.pathResolve('/a', 'b', 'c'), '/a/b/c');
			assert.strictEqual(alchemy.pathResolve('/a'), '/a');
		});
	});

	describe('#addViewDirectory(path, weight = 10)', function() {
		it('adds a new view directory', function() {
			let test_views = alchemy.pathResolve(__filename, '..', 'view');
			alchemy.addViewDirectory(test_views);
		});
	});

	describe('#styleMiddleware(req, res, next)', function() {
		it('is the middleware that compiles & serves CSS, LESS & SCSS files', function(done) {
			var url = 'http://localhost:' + alchemy.settings.port + '/stylesheets/alchemy-info.css';

			Blast.fetch(url, function gotResponse(err, res, body) {

				if (err) {
					return done(err);
				}

				assert.strictEqual(res.statusCode, 200);
				assert.strictEqual(res.headers['content-type'], 'text/css; charset=utf-8');
				assert.strictEqual(body.length > 100, true);
				done();
			});
		});
	});

	describe('#scriptMiddleware(req, res, next)', function() {
		it('is the middleware that serves script files', function(done) {
			var url = 'http://localhost:' + alchemy.settings.port + '/scripts/alchemy.js';

			Blast.fetch(url, function gotResponse(err, res, body) {

				if (err) {
					return done(err);
				}

				assert.strictEqual(res.statusCode, 200);
				assert.strictEqual(res.headers['content-type'], 'application/javascript; charset=utf-8');
				assert.strictEqual(body.length > 100, true);
				done();
			});
		});
	});
});
@@ -1123,24 +1123,152 @@
 unction() %7B%0A
+%0A%09%09%09if (process.platform == 'win32') %7B%0A%09%09%09%09assert.strictEqual(alchemy.pathResolve('/a', 'b', 'c'), 'C:%5C%5Ca%5C%5Cb%5C%5Cc');%0A%09%09%09%7D else %7B%0A%09
 %09%09%09assert.st
@@ -1321,24 +1321,25 @@
  '/a/b/c');%0A
+%09
 %09%09%09assert.st
@@ -1382,16 +1382,21 @@
  '/a');%0A
+%09%09%09%7D%0A
 %09%09%7D);%0A%09%7D

Fix pathResolve unit test on windows