<commit_before>var assert = require('chai').assert;
var sinon = require('sinon');
var EventEmitter = require('async-eventemitter');
var sockMon = require('../index.js');
var storage = require('node-persist');
var bcrypt = require('bcryptjs');

//dependencies to mock
var bot = require("sockbot");
var Hapi = require('hapi');

describe("The command-line parser", function() {
	var sandbox, mockCMD, processInputSpy, mockOut;

	beforeEach(function() {
		sandbox = sinon.sandbox.create();
		mockCMD = new EventEmitter();
		mockCMD.setEncoding = function() {};
		processInputSpy = sandbox.spy(sockMon, "processInput");

		//Very briefly mock out process.openstdin, then restore it
		var mockOpen = sandbox.stub(process,"openStdin").returns(mockCMD);
		//Also shut up the console
		mockOut = sandbox.stub(sockMon,"respond");
		sockMon.init();
		mockOpen.restore();
	})

	afterEach(function() {
		sandbox.restore();
	})

	it("should be able to respond", function() {
		var mockConsole = sandbox.stub(console, "log");
		var string = "the quick brown fox jumps over the lazy dog";
		sockMon.respond(string);
		assert(mockConsole.called,"Console log should be called");
		assert.equal(mockConsole.firstCall.args[0],string);
	});

	it("should exit when asked", function(done) {
		var mockExit = sandbox.stub(process,"exit").returns();

		mockCMD.emit("data","exit", function() {
			assert(processInputSpy.called,"ProcessInput should be called");
			assert(mockExit.called,"Exit should be called");
			done();
		});

	});

	it("should start the server the first time it's asked", function(done) {
		var startServer = sandbox.stub(sockMon,"startServer");

		mockCMD.emit("data","start", function() {
			assert(processInputSpy.called,"ProcessInput should be called");
			assert(startServer.calledOnce,"StartServer shuld be called");
			done();
		});

	});

	it("should not start the server if it's already running", function(done) {
		var startServer = sandbox.spy(sockMon,"startServer");
		sandbox.stub(Hapi.Server.prototype,"start"); //don't actually start
		sandbox.stub(Hapi.Server.prototype,"route");<commit_msg>make that respond test work<commit_after>var assert = require('chai').assert;
var sinon = require('sinon');
var EventEmitter = require('async-eventemitter');
var sockMon = require('../index.js');
var storage = require('node-persist');
var bcrypt = require('bcryptjs');

//dependencies to mock
var bot = require("sockbot");
var Hapi = require('hapi');

describe("The command-line parser", function() {
	var sandbox, mockCMD, processInputSpy, mockOut;

	beforeEach(function() {
		sandbox = sinon.sandbox.create();
		mockCMD = new EventEmitter();
		mockCMD.setEncoding = function() {};
		processInputSpy = sandbox.spy(sockMon, "processInput");

		//Very briefly mock out process.openstdin, then restore it
		var mockOpen = sandbox.stub(process,"openStdin").returns(mockCMD);
		//Also shut up the console
		mockOut = sandbox.stub(sockMon,"respond");
		sockMon.init();
		mockOpen.restore();
	})

	afterEach(function() {
		sandbox.restore();
	})

	it("should be able to respond", function() {
		var mockConsole = sandbox.stub(console, "log");
		var string = "the quick brown fox jumps over the lazy dog";
		mockOut.restore();
		sockMon.respond(string);
		assert(mockConsole.called,"Console log should be called");
		assert.equal(mockConsole.firstCall.args[0],string);
	});

	it("should exit when asked", function(done) {
		var mockExit = sandbox.stub(process,"exit").returns();

		mockCMD.emit("data","exit", function() {
			assert(processInputSpy.called,"ProcessInput should be called");
			assert(mockExit.called,"Exit should be called");
			done();
		});

	});

	it("should start the server the first time it's asked", function(done) {
		var startServer = sandbox.stub(sockMon,"startServer");

		mockCMD.emit("data","start", function() {
			assert(processInputSpy.called,"ProcessInput should be called");
			assert(startServer.calledOnce,"StartServer shuld be called");
			done();
		});

	});

	it("should not start the server if it's already running", function(done) {
		var startServer = sandbox.spy(sockMon,"startServer");
		sandbox.stub(Hapi.Server.prototype,"start"); //don't actually start
		sandbox.stub(Hapi.Server.prototype,"route");
{'fraction_non_alphanumeric': 0.15507895357058685, 'fraction_numerical': 0.0004713646005185011, 'mean_word_length': 5.250368188512518, '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': '2050066', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1293, 'n_words': 320}