<commit_before>
'use strict';

const tape = require('tape');
const sinon = require('sinon');

const request = require('request');
const postStub = sinon.stub(request, 'post');

const engine = require('../../../index');


const config = require('../../../config');
const playerStatus = require('../../../poker-engine/domain/player-status');

const getSymbol = require('../../test-utils/get-symbol');

const sut = require('../../../poker-engine/domain-utils/player-factory');



tape('player factory', t => t.end());

tape('cant create invalid player', function(t) {

  const player = sut({ name: 'arale' });

  t.strictEqual(player, null, '');
  t.end();
});

tape('create new player', function(t) {

  const player = sut({ name: 'arale', id: 'a1', serviceUrl: 'http:arale.com' });

  t.strictEqual(player.id, 'a1');
  t.strictEqual(player.name, 'arale');
  t.strictEqual(player.serviceUrl, 'http:arale.com');

  t.strictEqual(player.status, 'active', 'player is active');
  t.strictEqual(player.chips, config.BUYIN, 'player has chips');
  t.strictEqual(player.chipsBet, 0, 'player hasnt bet anything yet')
  t.ok(Array.isArray(player.cards), 'player cards');

  t.equal(typeof player.payBet, 'function', 'player can bet');
  t.equal(typeof player.pay, 'function', 'player can pay');

  t.end();
});




tape('player#pay', t => t.end());

tape('player pay call internal bet method', function(t) {

  const gamestate = {};
  const player = sut({ name: 'arale', id: 'a1', serviceUrl: 'http:arale.com' });

  const updateStub = sinon.stub(player, getSymbol(Object.getPrototypeOf(player), 'internal-update-method'));

  player.pay(gamestate, 50);

  t.ok(updateStub.calledOnce);
  t.ok(updateStub.calledWith(gamestate, 50));
<commit_msg>test update post bet<commit_after>
'use strict';

const tape = require('tape');
const sinon = require('sinon');

const request = require('request');
const postStub = sinon.stub(request, 'post');

const engine = require('../../../index');


const config = require('../../../config');
const playerStatus = require('../../../poker-engine/domain/player-status');

const getSymbol = require('../../test-utils/get-symbol');
const isAllin_ = Symbol.for('is-all-in');

const sut = require('../../../poker-engine/domain-utils/player-factory');



tape('player factory', t => t.end());

tape('cant create invalid player', function(t) {

  const player = sut({ name: 'arale' });

  t.strictEqual(player, null, '');
  t.end();
});

tape('create new player', function(t) {

  const player = sut({ name: 'arale', id: 'a1', serviceUrl: 'http:arale.com' });

  t.strictEqual(player.id, 'a1');
  t.strictEqual(player.name, 'arale');
  t.strictEqual(player.serviceUrl, 'http:arale.com');

  t.strictEqual(player.status, 'active', 'player is active');
  t.strictEqual(player.chips, config.BUYIN, 'player has chips');
  t.strictEqual(player.chipsBet, 0, 'player hasnt bet anything yet')
  t.ok(Array.isArray(player.cards), 'player cards');

  t.equal(typeof player.fold, 'function', 'player can fold');
  t.equal(typeof player.payBet, 'function', 'player can bet');
  t.equal(typeof player.pay, 'function', 'player can pay');
  t.equal(typeof player.talk, 'function', 'player can talk');

  t.end();
});




tape('player update gamestate (internal)', t => t.end());

tape('internal gamestate update', function(t) {

  const arale = sut({ name: 'arale', id: 'a1', serviceUrl: 'http:arale.com' });

  const bender = sut({ name: 'bender', id: 'b2', serviceUrl: 'http:bender.com' });

  const marvin = sut({ name: 'marvin', id: 'm3', serviceUrl: 'http:marvin.com' });
  marvin.chips = 50;

  const gamestate = { pot: 150, sidepots: [], callAmount: 100, players: [arale, bender, marvin] };

  const update_ = getSymbol(Object.getPrototypeOf(arale), 'internal-update-method');

  arale[update_](gamestate, 100);

  t.equal(arale[isAllin_], false);
  t.equal(arale.chipsBet, 100);
  t.equal(arale.chips, 400);
  t.equal(gamestate.pot, 250);
  t.equal(gamestate.callAmount, 100);
  t.equal(gamestate.sidepots.length, 0);



  bender[update_](gamestate, 300);

  t.equal(bender[isAllin_], false);
  t.equal(bender.chipsBet, 300);
  t.equal(bender.chips, 200);
  t.equal(gamestate.pot, 550);
  t.equal(gamestate.callAmount, 300);
  t.equal(gamestate.sidepots.length, 0);



  marvin[update_](gamestate, 50);

  t.equal(marvin[isAllin_], true);
  t.equal(marvin.chipsBet, 50);
  t.equal(marvin.chips, 0);
  t.equal(gamestate.pot, 600);
  t.equal(gamestate.callAmount, 50);
  t.equal(gamestate.sidepots.length, 2);
  t.equal(gamestate.sidepots[0].quote, 50);
  t.equal(gamestate.sidepots[0].amount, 150);
  t.equal(gamestate.sidepots[1].quote, 300);
  t.equal(gamestate.sidepots[1].amount, 300);

  t.end();

});




tape('player#pay', t => t.end());

tape('player pay call internal bet method', function(t) {

  const gamestate = {};
  const player = sut({ name: 'arale', id: 'a1', serviceUrl: 'http:arale.com' });

  const updateStub = sinon.stub(player, getSymbol(Object.getPrototypeOf(player), 'internal-update-method'));

  player.pay(gamestate, 50);

  t.ok(updateStub.calledOnce);
  t.ok(updateStub.calledWith(gamestate, 50));

{'fraction_non_alphanumeric': 0.19964939618231398, 'fraction_numerical': 0.016556291390728478, 'mean_word_length': 4.533405172413793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '5707179', 'n_tokens_mistral': 1969, 'n_tokens_neox': 1849, 'n_words': 385}