<commit_before>/*
Name: Routes Test
Project: Maelström - World
Author: demiurgosoft <<EMAIL>>
Description: Routes test
*/

var assert = require('chai').assert;
var request = require('supertest');
var async = require('async');

var map = require('../app/map');
var World = require('../app/world');

var serverTest = require('./config/server');
var populate = require('./config/populate');
var data = require('./config/data');

describe('Routes', function() {
	describe('GET Routes', function() {
		var app;
		before(function(done) {
			populate(function() {
				serverTest.startServer(function() {
					app = serverTest.app;
					done();
				});
			});
		});
		after(function() {
			serverTest.stopServer();
			populate.clear();
		});
		it('/map', function(done) {
			request(app)
				.get('/map')
				.expect('Content-Type', /json/)
				.expect(200)
				.end(function(err, res) {
					assert.notOk(err);
					assert.ok(res);
					assert.isArray(res.body);
					var body = res.body;
					assert.equal(body.length, Object.keys(data.cities).length);
					for (var i = 0; i < body.length; i++) {
						assert.ok(body[i]);
						assert.ok(map.isCity(body[i]));
					}
					done();
				});
		});
		it('/city/:city_name', function(done) {
			map.getAllCities(function(err, cities) {
				assert.notOk(err);
				assert.ok(cities);
				async.each(cities, function(cityName, cb) {
					request(app)
						.get('/city/' + cityName)
						.expect('Content-Type', /json/)
						.expect(200)
						.end(function(err, res) {
							assert.notOk(err);
							assert.ok(res);
							var body = res.body;
							assert.ok(body.name);
							assert.ok(body.position);
							assert.strictEqual(body.position.length, 2);
							assert.ok(body.slug);
							cb();
						});
				}, function(err) {
					assert.notOk(err);
					done();
				});
			});
		});
		it('/city/products/:city_name', function(done) {
			map.getAllCities(function(err, cities) {
				assert.notOk(err);
				assert.ok(cities);
				async.each(cities, function(cityName, cb) {
					request(app)
						.get('/city/products/' + cityName)
						.expect('Content-Type', /json/)
						.expect(200)
						.end(function(err, res) {
							assert.notOk(err);
							assert.ok(res);
							var body = res.body;
							for (var p in data.products) {
								var pname = data.products[p].name;
								assert.ok(body[pname]);
								assert.strictEqual(body[pname].quantity, 10);
								assert.strictEqual(body[pname].production, 1);
							}
							cb();
						});
				}, function(err) {
					assert.notOk(err);
					done();
				});
			});
		});
		it('/ship_models', function(done) {
			request(app)
				.get('/ship_models')
				.expect('Content-Type', /json/)
				.expect(200)
				.end(function(err, res) {
					assert.notOk(err);
					assert.ok(res.body);
					var body = res.body;
					assert.typeOf(body, 'array');
					for (var i = 0; i < body.length; i++) {
						var s = body[i];
						assert.ok(s.name);
						assert.ok(s.life);
						assert.ok(s.speed);
						assert.ok(s.price);
						assert.ok(s.cargo);
						assert.ok(s.slug);
					}
					done();
				});
		});
		it.skip('/products',function(done){
			return done(new Error("Not implemented"));
		});
		it('/user/ships', function(done) {
			var token = data.users.arthur.token;
			request(app)
				.get('/user/ships')
				.set('Authorization', "Bearer " + token)
				.expect('Content-Type', /json/)
				.expect(200)
				.end(function(err, res) {
					assert.notOk(err);
					assert.ok(res);
					assert.ok(res.body);
					assert.strictEqual(res.body.length, 1);
					request(app)
						.get('/user/ships')
						.expect(401)
						.expect('Content-Type', /json/)
						.end(function(err, res) {
							assert.notOk(err);
							assert.ok(res.body);
							assert.ok(res.body.err);
							done();
						});
				});
		});
		it('user/ship/:ship_id', function(done) {
			var userData = data.users.arthur;
			var token = userData.token;
			var shipData = data.userShips.blackPearl;<commit_msg>test /products<commit_after>/*
Name: Routes Test
Project: Maelström - World
Author: demiurgosoft <<EMAIL>>
Description: Routes test
*/

var assert = require('chai').assert;
var request = require('supertest');
var async = require('async');

var map = require('../app/map');
var World = require('../app/world');

var serverTest = require('./config/server');
var populate = require('./config/populate');
var data = require('./config/data');

describe('Routes', function() {
	describe('GET Routes', function() {
		var app;
		before(function(done) {
			populate(function() {
				serverTest.startServer(function() {
					app = serverTest.app;
					done();
				});
			});
		});
		after(function() {
			serverTest.stopServer();
			populate.clear();
		});
		it('/map', function(done) {
			request(app)
				.get('/map')
				.expect('Content-Type', /json/)
				.expect(200)
				.end(function(err, res) {
					assert.notOk(err);
					assert.ok(res);
					assert.isArray(res.body);
					var body = res.body;
					assert.equal(body.length, Object.keys(data.cities).length);
					for (var i = 0; i < body.length; i++) {
						assert.ok(body[i]);
						assert.ok(map.isCity(body[i]));
					}
					done();
				});
		});
		it('/city/:city_name', function(done) {
			map.getAllCities(function(err, cities) {
				assert.notOk(err);
				assert.ok(cities);
				async.each(cities, function(cityName, cb) {
					request(app)
						.get('/city/' + cityName)
						.expect('Content-Type', /json/)
						.expect(200)
						.end(function(err, res) {
							assert.notOk(err);
							assert.ok(res);
							var body = res.body;
							assert.ok(body.name);
							assert.ok(body.position);
							assert.strictEqual(body.position.length, 2);
							assert.ok(body.slug);
							cb();
						});
				}, function(err) {
					assert.notOk(err);
					done();
				});
			});
		});
		it('/city/products/:city_name', function(done) {
			map.getAllCities(function(err, cities) {
				assert.notOk(err);
				assert.ok(cities);
				async.each(cities, function(cityName, cb) {
					request(app)
						.get('/city/products/' + cityName)
						.expect('Content-Type', /json/)
						.expect(200)
						.end(function(err, res) {
							assert.notOk(err);
							assert.ok(res);
							var body = res.body;
							for (var p in data.products) {
								var pname = data.products[p].name;
								assert.ok(body[pname]);
								assert.strictEqual(body[pname].quantity, 10);
								assert.strictEqual(body[pname].production, 1);
							}
							cb();
						});
				}, function(err) {
					assert.notOk(err);
					done();
				});
			});
		});
		it('/ship_models', function(done) {
			request(app)
				.get('/ship_models')
				.expect('Content-Type', /json/)
				.expect(200)
				.end(function(err, res) {
					assert.notOk(err);
					assert.ok(res.body);
					var body = res.body;
					assert.typeOf(body, 'array');
					for (var i = 0; i < body.length; i++) {
						var s = body[i];
						assert.ok(s.name);
						assert.ok(s.life);
						assert.ok(s.speed);
						assert.ok(s.price);
						assert.ok(s.cargo);
						assert.ok(s.slug);
					}
					done();
				});
		});
		it('/products',function(done){
			request(app)
				.get('/products')
				.expect('Content-Type', /json/)
				.expect(200)
				.end(function(err, res) {
					assert.notOk(err);
					assert.ok(res);
					assert.ok(res.body);
					assert.strictEqual(res.body.length,3);
					assert.ok(res.body[0]);
					done();
				});
		});
		it('/user/ships', function(done) {
			var token = data.users.arthur.token;
			request(app)
				.get('/user/ships')
				.set('Authorization', "Bearer " + token)
				.expect('Content-Type', /json/)
				.expect(200)
				.end(function(err, res) {
					assert.notOk(err);
					assert.ok(res);
					assert.ok(res.body);
					assert.strictEqual(res.body.length, 1);
					request(app)
						.get('/user/ships')
						.expect(401)
						.expect('Content-Type', /json/)
						.end(function(err, res) {
							assert.notOk(err);
							assert.ok(res.body);
							assert.ok(res.body.err);
							done();
						});
				});
		});
		it('user/ship/:ship_id', function(done) {
			var userData = data.users.arthur;
			var token = userData.token;
			var shipData = data.userShips.blackPearl;
{'fraction_non_alphanumeric': 0.1909866017052375, 'fraction_numerical': 0.006699147381242387, 'mean_word_length': 2.50597779675491, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2588361', 'n_tokens_mistral': 3938, 'n_tokens_neox': 2853, 'n_words': 469}