<commit_before>"use strict";

var peg = require('../src/MatrixClientPeg.js');
var jssdk = require('matrix-js-sdk');
var MatrixEvent = jssdk.MatrixEvent;
var sinon = require('sinon');

/**
 * Perform common actions before each test case, e.g. printing the test case
 * name to stdout.
 * @param {Mocha.Context} context  The test context
 */
module.exports.beforeEach = function(context) {
    var desc = context.currentTest.fullTitle();
    console.log();
    console.log(desc);
    console.log(new Array(1 + desc.length).join("="));
};


/**
 * Stub out the MatrixClient, and configure the MatrixClientPeg object to
 * return it when get() is called.
 *
 * @returns {sinon.Sandbox}; remember to call sandbox.restore afterwards.
 */
module.exports.stubClient = function() {
    var sandbox = sinon.sandbox.create();

    // 'sandbox.restore()' doesn't work correctly on inherited methods,
    // so we do this for each method
    var methods = ['get', 'unset', 'replaceUsingUrls',
                   'replaceUsingAccessToken'];
    for (var i = 0; i < methods.length; i++) {
        sandbox.stub(peg, methods[i]);
    }

    var matrixClientStub = sinon.createStubInstance(jssdk.MatrixClient);
    peg.get.returns(matrixClientStub);
    return sandbox;
}


/**
 * Create an Event.
 * @param {Object} opts Values for the event.
 * @param {string} opts.type The event.type<commit_msg>Build our own stub MatrixClient for the tests<commit_after>"use strict";

var sinon = require('sinon');
var q = require('q');

var peg = require('../src/MatrixClientPeg.js');
var jssdk = require('matrix-js-sdk');
var MatrixEvent = jssdk.MatrixEvent;

/**
 * Perform common actions before each test case, e.g. printing the test case
 * name to stdout.
 * @param {Mocha.Context} context  The test context
 */
module.exports.beforeEach = function(context) {
    var desc = context.currentTest.fullTitle();
    console.log();
    console.log(desc);
    console.log(new Array(1 + desc.length).join("="));
};


/**
 * Stub out the MatrixClient, and configure the MatrixClientPeg object to
 * return it when get() is called.
 *
 * @returns {sinon.Sandbox}; remember to call sandbox.restore afterwards.
 */
module.exports.stubClient = function() {
    var sandbox = sinon.sandbox.create();

    var client = {
        getHomeserverUrl: sinon.stub(),
        getIdentityServerUrl: sinon.stub(),

        getPushActionsForEvent: sinon.stub(),
        getRoom: sinon.stub(),
        loginFlows: sinon.stub(),
        on: sinon.stub(),

        paginateEventTimeline: sinon.stub().returns(q()),
        sendReadReceipt: sinon.stub().returns(q()),
    };

    // create the peg

    // 'sandbox.restore()' doesn't work correctly on inherited methods,
    // so we do this for each method
    var methods = ['get', 'unset', 'replaceUsingUrls',
                   'replaceUsingAccessToken'];
    for (var i = 0; i < methods.length; i++) {
        sandbox.stub(peg, methods[i]);
    }
    peg.get.returns(client);
    return sandbox;
}


/**
 * Create an Event.
 * @param {Object} opts Values for the event.
 * @param {string} opts.type The event.type
{'fraction_non_alphanumeric': 0.1405648267008986, 'fraction_numerical': 0.0012836970474967907, 'mean_word_length': 3.252387448840382, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4396466', 'n_tokens_mistral': 972, 'n_tokens_neox': 957, 'n_words': 273}