<commit_before>var User = require('../User.js');
var Room = require('../Room.js');
var rooms;
describe("User", function() {
  var user;

  beforeEach(function() {
    user = new User();
    // clear the rooms
    rooms = Room.getRooms();
    rooms.splice(0,rooms.length);
  });

  it("should initialize important game data to false or empty objects", function() {
    expect(user.bets).toEqual(false);
    expect(user.drawboard).toEqual({});
    expect(user.room).toEqual(false);
    expect(user.answerSubmitted).toEqual(false);
  });

  describe("serialize(notRecursive)", function() {
    beforeEach(function() {
      user.socket = "testDon'tWork";
      user.username = "name";
      user.accessToken = "access";
      user.bets = ['test1', 'test2'];
      user.drawboard = { data: 'test' };
      user.room = false;
      user.answerSubmitted = true;
    });

    it("should serialize the main user data into json.stringify-able object", function() {
      var output = user.serialize();
      expect(output.username).toEqual(user.username);
      expect(output.accessToken).not.toBeDefined();
      expect(output.socket).not.toBeDefined();
      expect(output.room).toEqual(false);
      expect(output.drawboard).toEqual(user.drawboard);
      expect(output.bets).toEqual(user.bets);
    });

    it("should call user.room.serialize() if Room is defined and notRecursive is undefined", function() {
      user.room = { serialize: function() {} };
      spyOn(user.room, 'serialize');
      var output = user.serialize();
      expect(user.room.serialize).toHaveBeenCalled();
    });

    it("should not include user.room or call user.room.serialize() if notRecursive is true", function() {
      user.room = { serialize: function() {} };
      spyOn(user.room, 'serialize');
      var output = user.serialize(true);
      expect(user.room.serialize).not.toHaveBeenCalled();
      expect(output.room).not.toBeDefined();
    });
  });
  describe('createRoom(roomName)', function() {
    var roomName = 'testroom';

    it('should not create a room if it already exists in the rooms global', function() {
      rooms[roomName] = "test";
      user.room = false;
      expect(user.createRoom(roomName)).toEqual("A room with this name already exists.");
    });
    it('should not create a room if the user is already in a room', function() {
      user.room = 'test';
      delete rooms[roomName];
      expect(user.createRoom(roomName)).toEqual("You must leave your current room.");
    });
  });
});<commit_msg>Added more specs to User<commit_after>var User = require('../User.js');
var Room = require('../Room.js');
var rooms;
describe("User", function() {
  var user;

  beforeEach(function() {
    user = new User();
    // clear the rooms
    rooms = Room.getRooms();
  });

  it("should initialize important game data to false or empty objects", function() {
    expect(user.bets).toEqual(false);
    expect(user.drawboard).toEqual({});
    expect(user.room).toEqual(false);
    expect(user.answerSubmitted).toEqual(false);
  });

  describe("serialize(notRecursive)", function() {
    beforeEach(function() {
      user.socket = "testDon'tWork";
      user.username = "name";
      user.accessToken = "access";
      user.bets = ['test1', 'test2'];
      user.drawboard = { data: 'test' };
      user.room = false;
      user.answerSubmitted = true;
    });

    it("should serialize the main user data into json.stringify-able object", function() {
      var output = user.serialize();
      expect(output.username).toEqual(user.username);
      expect(output.accessToken).not.toBeDefined();
      expect(output.socket).not.toBeDefined();
      expect(output.room).toEqual(false);
      expect(output.drawboard).toEqual(user.drawboard);
      expect(output.bets).toEqual(user.bets);
    });

    it("should call user.room.serialize() if Room is defined and notRecursive is undefined", function() {
      user.room = { serialize: function() {} };
      spyOn(user.room, 'serialize');
      var output = user.serialize();
      expect(user.room.serialize).toHaveBeenCalled();
    });

    it("should not include user.room or call user.room.serialize() if notRecursive is true", function() {
      user.room = { serialize: function() {} };
      spyOn(user.room, 'serialize');
      var output = user.serialize(true);
      expect(user.room.serialize).not.toHaveBeenCalled();
      expect(output.room).not.toBeDefined();
    });
  });
  describe('createRoom(roomName)', function() {
    var roomName = 'testroom';

    it('should not create a room if it already exists', function() {
      rooms[roomName] = "test";
      user.room = false;
      expect(user.createRoom(roomName)).toEqual("A room with this name already exists.");
      expect(user.room).toEqual(false);
    });
    it('should not create a room if the user is already in a room', function() {
      user.room = 'test';
      delete rooms[roomName];
      expect(user.createRoom(roomName)).toEqual("You must leave your current room.");
      expect(user.room).toEqual('test');
    });
  });
  describe('joinRoom(roomName)', function() {
    var roomName = 'testroom';
    it("should fail if the room doesn't exist", function() {
      user.room = false;
      delete rooms[roomName];
      expect(user.joinRoom(roomName)).toEqual("This room does not exist.");
      expect(user.room).toEqual(false);
    });
    it("should not create a room if the user is already in a room", function() {
      user.room = 'test';
      rooms[roomName] = 'occupied';
      expect(user.joinRoom(roomName)).toEqual("You must leave your current room.");
      expect(user.room).toEqual('test');
    });
  });
});
{'fraction_non_alphanumeric': 0.15846126698429505, 'fraction_numerical': 0.0008823010411152286, 'mean_word_length': 3.300455235204856, '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': '1645887', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1665, 'n_words': 393}