var assert = require('assert');
var app = require('../../../app.js');
var request = require('supertest');
var jsonSchemaValidator = require('jsonschema').Validator;
var jsonValidator = new jsonSchemaValidator();

var apiRoute = '/list/moviedvd';

var rootListSchema = {
	id: '/RootListSchema',
	properties: {
		movies: '/ListSchema'
	},
	required: ['movies', 'total']
};

var listSchema = {
	id: '/ListSchema',
	type: 'array',
	items: '/ListReleaseSchema'
};

var listReleaseSchema = {
	id: '/ListReleaseSchema',
	type: 'object',
	properties: {
		movieId: {
			type: 'integer'
		},
		releaseDate: {
			type: 'string',
			format: 'date-time'
		},
		title: '/TitleSchema',
		year: {
			type: 'integer'
		}
	},
	required: ['movieID', 'releaseDate', 'title', 'year']
};

var titleSchema = {
	id: '/TitleSchema',
	type: 'array',
	items: '/TitleItemsSchema'
};

var titleItemsSchema = {
	id: '/TitleItemsSchema',
	type: 'object',
	properties: {
		version: {
			type: 'string'
		},
		title: {
			type: 'string'
		}
	},
	required: ['version', 'title']
};

jsonValidator.addSchema(rootListSchema);
jsonValidator.addSchema(listSchema);
jsonValidator.addSchema(listReleaseSchema);
jsonValidator.addSchema(titleSchema);
jsonValidator.addSchema(titleItemsSchema);

describe(apiRoute + ' integration test', function() {

	beforeEach(function() {
		this.server = request(app);
	});

	it('returns 200', function(done) {
	    this.server.get(apiRoute).expect(200, done);
	});

	it('returns application/json header', function (done) {
		this.server.get(apiRoute).expect('Content-Type', 'application/json; charset=utf-8').end(done);
	})

	it('has a valid json', function (done) {
		this.server.get(apiRoute).expect(200, function (error, response) {
			var validationResult = jsonValidator.validate(response.body, '/RootListSchema');
			validationResult.errors.forEach(function (error) {
				assert.equal(error.property, error.message + ' (Schema: ' + error.schema + ')');
			});
			done();
		})
	});
});
@@ -1,17 +1,17 @@
 var 
-asser
+expec
 t = requ
@@ -19,16 +19,21 @@
 re('
-assert')
+chai').expect
 ;%0Ava
@@ -1874,37 +1874,15 @@
 %09%09%09%09
-assert.equal(error.property, 
+expect(
 erro
@@ -1927,16 +1927,41 @@
 a + ')')
+.to.equal(error.property)
 ;%0A%09%09%09%7D);

use chai