<commit_before>/**
 * API Session Tests
 */

var frisby = require('frisby');
var	panaxui = require('../../panaxui');

var	hostname = panaxui.config.hostname,
	port = panaxui.config.port,
	url = 'http://' + hostname + ':' + port + '/api';

/**
 * Test login
 */
frisby.create('Login')
	.post(url + panaxui.api.login, {
		username: panaxui.config.username,
		password: <PASSWORD>
	})
	.expectStatus(200)
	.expectHeaderContains('content-type', 'application/json')
	.expectJSON({
		success: true,
		// data: {
		// 	userId: //ToDo: Special userId verification?
		// }
	})
	.expectJSONTypes({
		success: Boolean,
		data: {
			userId: String
		}
	})
	.after(get_sitemap) // Chain tests (sync http requests)
.toss();	

/**
 * Test get sitemap when logged in
 */
function get_sitemap(err, res, body) {

	// ToDo: Should be stateless: https://github.com/vlucas/frisby/issues/36

	//  Grab returned session cookie
    var cookie = res.headers['set-cookie'][0].split(';')[0];
	console.dir(cookie);

	frisby.create('Get sitemap')
	    .addHeader('Cookie', cookie) // Pass session cookie with each request
		.get(url + panaxui.api.sitemap)
		.expectStatus(200)
		.expectHeaderContains('content-type', 'application/json')
		.expectJSON({
			success: true
		})
		.expectJSONLength('data', function (val) {
			expect(val).toBeGreaterThan(0); // Custom matcher callback
		})
		.expectJSONTypes({
			success: Boolean,
			data: Array
		})
		.after(logout) // Chain tests (sync http requests)
	.toss()
}


/**
 * Test logout
 */
function logout(err, res, body) {
	frisby.create('Logout')
		.get(url + panaxui.api.logout)
		.expectStatus(200)
		.expectHeaderContains('content-type', 'application/json')
		.expectJSON({
			success: true
		})
		.expectJSONTypes({
			success: Boolean
		})
		.after(fail_sitemap) // Chain tests (sync http requests)
	.toss();
}

/**
 * Test logout
 */
function fail_sitemap(err, res, body) {
	frisby.create('Fail sitemap')
		.get(url + panaxui.api.sitemap)
		.expectStatus(500)
		.expectHeaderContains('content-type', 'application/json')
		.expectJSON({
			success: false
		})
		.expectJSONTypes({
			success: Boolean
		})
	.toss();
}<commit_msg>READ Entity: First initially failing test (TDD phase 1)<commit_after>/**
 * API Session Tests
 */

var frisby = require('frisby');
var	panaxui = require('../../panaxui');

var	hostname = panaxui.config.hostname,
	port = panaxui.config.port,
	url = 'http://' + hostname + ':' + port + '/api';

var session_cookie;

/**
 * Test Login
 */
frisby.create('Login')
	.post(url + panaxui.api.login, {
		username: panaxui.config.username,
		password: <PASSWORD>
	})
	.expectStatus(200)
	.expectHeaderContains('content-type', 'application/json')
	.expectJSON({
		success: true,
		// data: {
		// 	userId: //ToDo: Special userId verification?
		// }
	})
	.expectJSONTypes({
		success: Boolean,
		data: {
			userId: String
		}
	})
	.after(get_sitemap) // Chain tests (sync http requests)
.toss();	

/**
 * Test Get Sitemap (when logged in)
 */
function get_sitemap(err, res, body) {

	// ToDo: Should be stateless: https://github.com/vlucas/frisby/issues/36
	// Grab returned session cookie
    session_cookie = res.headers['set-cookie'][0].split(';')[0];

	frisby.create('Get Sitemap')
	    .addHeader('Cookie', session_cookie) // Pass session cookie with each request
		.get(url + panaxui.api.sitemap)
		.expectStatus(200)
		.expectHeaderContains('content-type', 'application/json')
		.expectJSON({
			success: true
		})
		.expectJSONLength('data', function (val) {
			expect(val).toBeGreaterThan(0); // Custom matcher callback
		})
		.expectJSONTypes({
			success: Boolean,
			data: Array
		})
		.after(read_entity) // Chain tests (sync http requests)
	.toss()
}

/**
 * Test Read Entity (when logged in)
 */
function read_entity(err, res, body) {

	frisby.create('Read Entity')
	    .addHeader('Cookie', session_cookie) // Pass session cookie with each request
		.get(url + panaxui.api.read)
		.expectStatus(200)
		.expectHeaderContains('content-type', 'application/json')
		.expectJSON({
			success: true
		})
		.expectJSONTypes({
			success: Boolean
		})
		.after(logout) // Chain tests (sync http requests)
	.toss()
}


/**
 * Test Logout
 */
function logout(err, res, body) {
	frisby.create('Logout')
		.get(url + panaxui.api.logout)
		.expectStatus(200)
		.expectHeaderContains('content-type', 'application/json')
		.expectJSON({
			success: true
		})
		.expectJSONTypes({
			success: Boolean
		})
		.after(fail_sitemap) // Chain tests (sync http requests)
	.toss();
}

/**
 * Test Fail Read Entity (when logged out)
 * ToDo
 */

/**
 * Test Fail Sitemap (when logged out)
 */

function fail_sitemap(err, res, body) {
	frisby.create('Fail Sitemap')
		.get(url + panaxui.api.sitemap)
		.expectStatus(500)
		.expectHeaderContains('content-type', 'application/json')
		.expectJSON({
			success: false
		})
		.expectJSONTypes({
			success: Boolean
		})
	.toss();
}
{'fraction_non_alphanumeric': 0.1663273615635179, 'fraction_numerical': 0.007736156351791531, 'mean_word_length': 3.5617455896007426, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5690608', 'n_tokens_mistral': 1883, 'n_tokens_neox': 1747, 'n_words': 376}