<commit_before>/* global describe, it, after */
"use strict";

let assert = require("assert");

let {Chatlog, submitEntry, addEntry} = require("./index"),
    {clone} = require("../../lib/proto"),
    {connect, disconnect} = require("../../lib/socketConn");

let socketUrl = "http://localhost:8080/wsauth";

describe("Chatlog", function() {
  let conn = connect(socketUrl);
  after(function() {
    disconnect(conn);
    conn = null;
  });

  describe("cloning", function() {

    it("expects a socketConn and a namespace", function() {
      assert.ok(clone(Chatlog, conn, "test"));
    });

    it("creates an object with an entryGroups array", function() {
      let cl = clone(Chatlog, conn, "test");
      assert.ok(cl.entryGroups);
    });
  });

  describe("submitEntry()", function() {
    let log = clone(Chatlog, conn, "test");
    it("sends an entry to the server", function() {
      submitEntry(log, "action", {
        content: "hops up and down",
        groupTag: "Tester"
      });
    });
  });

  describe("addEntry()", function() {
    let log = clone(Chatlog, conn, "test");
    it("adds a new entry", function(done) {
      let newEntry = { entryType: "test", groupTag: "group", content: "foo" };
      log.entryGroups.bind("add", function(_ev, newEntryGroups) {
        /* jshint unused:vars */
        let firstEntry = newEntryGroups[0].firstEntry;
        assert.equal(firstEntry.entryType, "test");
        assert.equal(firstEntry.groupTag, newEntry.groupTag);
        assert.equal(firstEntry.content, newEntry.content);
        log.entryGroups.unbind("add");
        done();
      });
      addEntry(log, newEntry);
    });
    it("groups entries with the same type and groupTag", function(done) {
      let newEntry = { entryType: "test", groupTag: "group", content: "bar" },
          group = log.entryGroups[0];
      group.entries.bind("add", function(_ev, newEntries) {
        /* jshint unused:vars */
        assert.equal(group.entries.length, 2);
        assert.equal(newEntries.length, 1);
        assert.equal(group.firstEntry.groupTag, "group");
        assert.equal(newEntries[0].content, "bar");
        assert.equal(group.entries[0].content, "foo");<commit_msg>Additional tests for chatlog<commit_after>/* global describe, it, after */
"use strict";

let assert = require("assert");

let {Chatlog, submitEntry, addEntry} = require("./index"),
    {clone} = require("../../lib/proto"),
    {connect, disconnect} = require("../../lib/socketConn");

let socketUrl = "http://localhost:8080/wsauth";

describe("Chatlog", function() {
  let conn = connect(socketUrl);
  after(function() {
    disconnect(conn);
    conn = null;
  });

  describe("cloning", function() {

    it("expects a socketConn and a namespace", function() {
      assert.ok(clone(Chatlog, conn, "test"));
    });

    it("creates an object with an entryGroups array", function() {
      let cl = clone(Chatlog, conn, "test");
      assert.ok(cl.entryGroups);
    });

    it("adds messages that come through the conn", function(done) {
      let cl = clone(Chatlog, conn, "chat");
      cl.entryGroups.bind("add", function() {
        assert.deepEqual(cl.entryGroups.length, 1);
        cl.entryGroups.unbind("add");
        done();
      });
      submitEntry(cl, "action", {
        content: "hops up and down",
        groupTag: "Kat"
      });
    });
  });

  describe("submitEntry()", function() {
    let log = clone(Chatlog, conn, "chat");
    it("sends an entry to the server", function() {
      submitEntry(log, "action", {
        content: "hops up and down",
        groupTag: "Tester"
      });
    });
  });

  describe("addEntry()", function() {
    let log = clone(Chatlog, conn, "test");
    it("adds a new entry", function(done) {
      let newEntry = { entryType: "test", groupTag: "group", content: "foo" };
      log.entryGroups.bind("add", function(_ev, newEntryGroups) {
        /* jshint unused:vars */
        let firstEntry = newEntryGroups[0].firstEntry;
        assert.equal(firstEntry.entryType, "test");
        assert.equal(firstEntry.groupTag, newEntry.groupTag);
        assert.equal(firstEntry.content, newEntry.content);
        log.entryGroups.unbind("add");
        done();
      });
      addEntry(log, newEntry);
    });
    it("groups entries with the same type and groupTag", function(done) {
      let newEntry = { entryType: "test", groupTag: "group", content: "bar" },
          group = log.entryGroups[log.entryGroups.length-1];
      group.entries.bind("add", function(_ev, newEntries) {
        /* jshint unused:vars */
        assert.equal(group.entries.length, 2);
        assert.equal(newEntries.length, 1);
        assert.equal(group.firstEntry.groupTag, "group");
        assert.equal(newEntries[0].content, "bar");
        assert.equal(group.entries[0].content, "foo");
{'fraction_non_alphanumeric': 0.17015110743117368, 'fraction_numerical': 0.004346926102256262, 'mean_word_length': 3.03338898163606, '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': '6421987', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1454, 'n_words': 336}