<commit_before>"use strict";
var expect = require('chai').expect;
var app = require('../server');
var request = require('supertest')(app);
var pg = require('pg');
var config = require('../config/config');

//TODO .expect('Content-Type', /json/) not working
//TODO Update get to return pages
//TODO Update test cases for that

function cleanupData(done) {
	var client = new pg.Client(config.postgres.conString);
	client.connect(function(err) {
	  if(err) throw err;
	  
	  client.query('truncate table book; truncate table page; truncate table book_pages;', function(err, result) {
		if(err) throw err;
		client.end();
		done();
	  });
	});
}

var validBody = (function() {
	var pages = [{number:1, text:'This is page 1'}, {number:2, text: 'This is page 2'}];
	var body = {title:'My Book', language: 'EN', author: 'Travis', pages : pages};
	return body;
})();


describe('Book routes', function() {
	
	beforeEach(function(done) {
		cleanupData(done);
	});
	
	//GET
	describe('GET books - ', function() {
		it('Should fetch empty body', function(done) {
			request.get('/api/v1/books')
				.send()
				.expect('Content-Type', /json/)<commit_msg>Fix tests when db needs to be created<commit_after>"use strict";
var expect = require('chai').expect;
var app = require('../server');
var request = require('supertest')(app);
var pg = require('pg');
var config = require('../config/config');

//TODO .expect('Content-Type', /json/) not working
//TODO Update get to return pages
//TODO Update test cases for that

function cleanupData(done) {
	var client = new pg.Client(config.postgres.conString);
	client.connect(function(err) {
	  if(err) throw err;
	  
	  client.query('truncate table book; truncate table page; truncate table book_pages;', function(err, result) {
		if(err) throw err;
		client.end();
		done();
	  });
	});
}

var validBody = (function() {
	var pages = [{number:1, text:'This is page 1'}, {number:2, text: 'This is page 2'}];
	var body = {title:'My Book', language: 'EN', author: 'Travis', pages : pages};
	return body;
})();


describe('Book routes', function() {
	
	//This is really dumb, but the database isn't created when the tests start
	before(function(done) {
		setTimeout(function() {
			done();
		},250);
	});
	
	beforeEach(function(done) {
		cleanupData(done);
	});
	
	//GET
	describe('GET books - ', function() {
		it('Should fetch empty body', function(done) {
			request.get('/api/v1/books')
				.send()
				.expect('Content-Type', /json/)
{'fraction_non_alphanumeric': 0.17849898580121704, 'fraction_numerical': 0.005273833671399594, 'mean_word_length': 4.1375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5952054', 'n_tokens_mistral': 854, 'n_tokens_neox': 792, 'n_words': 235}