<commit_before>'use strict';

import Persistence from 'JsonPersistence';
import sinon from 'sinon';
import leaveLadderHandler from  '../app/handlers/leaveLadderHandler';
import assert from 'assertthat';

describe('leavLadderHandler', () => {
    it('should remove all matches with the player', () => {
        //given
        let ladderToUpdate = {
            name: 'ladderName',
            matches: [
                {player1: 'player', player2: 'player2', winner: 'player2'},
                {player1: 'player', player2: 'player1', winner: 'player'},
                {player1: 'player', player2: 'player1', winner: ''},
                {player1: 'player1', player2: 'player2', winner: ''},
            ]
        };

        let parsedCommand = {
            playerName: 'player',
            arguments: ['leaveladder', ladderToUpdate.name]
        };

        let fsMock = {
            readFile(fileName, callback) {
                callback(null, JSON.stringify([ladderToUpdate]));
            },
            writeFile(filename, data) {
                ladderToUpdate = JSON.parse(data)[0];
            }
        };

        let persistence = new Persistence('filename', fsMock);
        
        let handler = leaveLadderHandler(persistence);
<commit_msg>typo, btw this closes #2<commit_after>'use strict';

import Persistence from 'JsonPersistence';
import sinon from 'sinon';
import leaveLadderHandler from  '../app/handlers/leaveLadderHandler';
import assert from 'assertthat';

describe('leaveLadderHandler', () => {
    it('should remove all matches with the player', () => {
        //given
        let ladderToUpdate = {
            name: 'ladderName',
            matches: [
                {player1: 'player', player2: 'player2', winner: 'player2'},
                {player1: 'player', player2: 'player1', winner: 'player'},
                {player1: 'player', player2: 'player1', winner: ''},
                {player1: 'player1', player2: 'player2', winner: ''},
            ]
        };

        let parsedCommand = {
            playerName: 'player',
            arguments: ['leaveladder', ladderToUpdate.name]
        };

        let fsMock = {
            readFile(fileName, callback) {
                callback(null, JSON.stringify([ladderToUpdate]));
            },
            writeFile(filename, data) {
                ladderToUpdate = JSON.parse(data)[0];
            }
        };

        let persistence = new Persistence('filename', fsMock);
        
        let handler = leaveLadderHandler(persistence);

{'fraction_non_alphanumeric': 0.13249211356466878, 'fraction_numerical': 0.01222397476340694, 'mean_word_length': 2.075151515151515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2342210', 'n_tokens_mistral': 701, 'n_tokens_neox': 673, 'n_words': 162}