<commit_before>var axios = require('axios');
var expect = require('chai').expect;

var MockAdapter = require('../src');

describe('MockAdapter basics', function() {
  var instance;
  var mock;

  beforeEach(function() {
    instance = axios.create();
    mock = new MockAdapter(instance);
  });

  it('correctly sets the adapter on the axios instance', function() {
    expect(instance.defaults.adapter).to.exist;
  });

  it('supports all verbs', function() {
    expect(mock.onGet).to.be.a('function');
    expect(mock.onPost).to.be.a('function');
    expect(mock.onPut).to.be.a('function');
    expect(mock.onHead).to.be.a('function');
    expect(mock.onDelete).to.be.a('function');
    expect(mock.onPatch).to.be.a('function');
  });

  it('registers the mock handlers on the mock instance', function() {
    mock.onGet('/foo').reply(200, { foo: 'bar' }, { baz: 'quux' });

    expect(mock.handlers['get'][0][0]).to.equal('/foo');
    expect(mock.handlers['get'][0][1]).to.equal(200);
    expect(mock.handlers['get'][0][2].foo).to.equal('bar');
    expect(mock.handlers['get'][0][3].baz).to.equal('quux');
  });

  it('registers the mock handlers with body on the mock instance', function() {
    var body = { foo: 'bar' };
    var response = { foo: 'bar' };
    var headers = { baz: 'quux' };
    mock.onGet('/foo', body).reply(200, response, headers);

    expect(mock.handlers['get'][0][0]).to.equal('/foo');
    expect(mock.handlers['get'][0][1]).to.equal(200);
    expect(mock.handlers['get'][0][2]).to.eql(response);
    expect(mock.handlers['get'][0][3]).to.equal(headers);
    expect(mock.handlers['get'][0][4]).to.eql(body);
  });

  it('mocks requests', function() {
    mock.onGet('/foo').reply(200, {
      foo: 'bar'
    });

    return instance.get('/foo')
      .then(function(response) {
        expect(response.status).to.equal(200);
        expect(response.data.foo).to.equal('bar');
      });
  });

  it('exposes the adapter', function() {
    expect(mock.adapter()).to.be.a('function');

    instance.defaults.adapter = mock.adapter();

    mock.onGet('/foo').reply(200, {
      foo: 'bar'
    });

    instance.get('/foo')
      .then(function(response) {
        expect(response.status).to.equal(200);
        expect(response.data.foo).to.equal('bar');
        done();
      });
  });

  it('can return headers', function() {
    mock.onGet('/foo').reply(200, {}, {
      foo: 'bar'
    });

    return instance.get('/foo')
      .then(function(response) {
        expect(response.status).to.equal(200);
        expect(response.headers.foo).to.equal('bar');
      });
  });

  it('accepts a callback that returns a response', function() {
    mock.onGet('/foo').reply(function() {
      return [200, { foo: 'bar' }];
    });

    return instance.get('/foo')
      .then(function(response) {
        expect(response.status).to.equal(200);
        expect(response.data.foo).to.equal('bar');
      });
  });

  it('matches on a regex', function() {
    mock.onGet(/\/fo+/).reply(200);

    return instance.get('/foooooooooo')
      .then(function(response) {
        expect(response.status).to.equal(200);
      });
  });

  it('can pass a body to match to a handler', function() {
    var body = { body: { is: 'passed' }, in: true };
    mock.onPost('/withBody', body).reply(200);

    return instance.post('/withBody', body)
      .then(function(response) {
        expect(response.status).to.equal(200);
      });
  });

  it('does not match when body is wrong', function() {
    var body = { body: { is: 'passed' }, in: true };
    mock.onPatch('/wrongObjBody', body).reply(200);

    return instance.patch('/wrongObjBody', { wrong: 'body' })
      .catch(function(error) {
        expect(error.response.status).to.equal(404);
      });
  });

  it('does not match when string body is wrong', function() {
    mock.onPatch('/wrongStrBody', 'foo').reply(200);

    return instance.patch('/wrongStrBody', 'bar')
      .catch(function(error) {<commit_msg>Test deep equality check in tests<commit_after>var axios = require('axios');
var expect = require('chai').expect;

var MockAdapter = require('../src');

describe('MockAdapter basics', function() {
  var instance;
  var mock;

  beforeEach(function() {
    instance = axios.create();
    mock = new MockAdapter(instance);
  });

  it('correctly sets the adapter on the axios instance', function() {
    expect(instance.defaults.adapter).to.exist;
  });

  it('supports all verbs', function() {
    expect(mock.onGet).to.be.a('function');
    expect(mock.onPost).to.be.a('function');
    expect(mock.onPut).to.be.a('function');
    expect(mock.onHead).to.be.a('function');
    expect(mock.onDelete).to.be.a('function');
    expect(mock.onPatch).to.be.a('function');
  });

  it('registers the mock handlers on the mock instance', function() {
    mock.onGet('/foo').reply(200, { foo: 'bar' }, { baz: 'quux' });

    expect(mock.handlers['get'][0][0]).to.equal('/foo');
    expect(mock.handlers['get'][0][1]).to.equal(200);
    expect(mock.handlers['get'][0][2].foo).to.equal('bar');
    expect(mock.handlers['get'][0][3].baz).to.equal('quux');
  });

  it('registers the mock handlers with body on the mock instance', function() {
    var body = { foo: 'bar' };
    var response = { foo: 'bar' };
    var headers = { baz: 'quux' };
    mock.onGet('/foo', body).reply(200, response, headers);

    expect(mock.handlers['get'][0][0]).to.equal('/foo');
    expect(mock.handlers['get'][0][1]).to.equal(200);
    expect(mock.handlers['get'][0][2]).to.eql(response);
    expect(mock.handlers['get'][0][3]).to.equal(headers);
    expect(mock.handlers['get'][0][4]).to.eql(body);
  });

  it('mocks requests', function() {
    mock.onGet('/foo').reply(200, {
      foo: 'bar'
    });

    return instance.get('/foo')
      .then(function(response) {
        expect(response.status).to.equal(200);
        expect(response.data.foo).to.equal('bar');
      });
  });

  it('exposes the adapter', function() {
    expect(mock.adapter()).to.be.a('function');

    instance.defaults.adapter = mock.adapter();

    mock.onGet('/foo').reply(200, {
      foo: 'bar'
    });

    instance.get('/foo')
      .then(function(response) {
        expect(response.status).to.equal(200);
        expect(response.data.foo).to.equal('bar');
        done();
      });
  });

  it('can return headers', function() {
    mock.onGet('/foo').reply(200, {}, {
      foo: 'bar'
    });

    return instance.get('/foo')
      .then(function(response) {
        expect(response.status).to.equal(200);
        expect(response.headers.foo).to.equal('bar');
      });
  });

  it('accepts a callback that returns a response', function() {
    mock.onGet('/foo').reply(function() {
      return [200, { foo: 'bar' }];
    });

    return instance.get('/foo')
      .then(function(response) {
        expect(response.status).to.equal(200);
        expect(response.data.foo).to.equal('bar');
      });
  });

  it('matches on a regex', function() {
    mock.onGet(/\/fo+/).reply(200);

    return instance.get('/foooooooooo')
      .then(function(response) {
        expect(response.status).to.equal(200);
      });
  });

  it('can pass a body to match to a handler', function() {
    mock
      .onPost('/withBody', { body: { is: 'passed' }, in: true })
      .reply(200);

    return instance.post('/withBody', { body: { is: 'passed' }, in: true })
      .then(function(response) {
        expect(response.status).to.equal(200);
      });
  });

  it('does not match when body is wrong', function() {
    var body = { body: { is: 'passed' }, in: true };
    mock.onPatch('/wrongObjBody', body).reply(200);

    return instance.patch('/wrongObjBody', { wrong: 'body' })
      .catch(function(error) {
        expect(error.response.status).to.equal(404);
      });
  });

  it('does not match when string body is wrong', function() {
    mock.onPatch('/wrongStrBody', 'foo').reply(200);

    return instance.patch('/wrongStrBody', 'bar')
      .catch(function(error) {
{'fraction_non_alphanumeric': 0.2108682073703935, 'fraction_numerical': 0.018738288569643973, 'mean_word_length': 3.1828631138975965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '1506454', 'n_tokens_mistral': 2757, 'n_tokens_neox': 2619, 'n_words': 448}