<commit_before>import axios from 'axios';
import { call } from 'redux-saga/effects';

import axiosDriver from './axios-driver';

describe('axios driver', () => {
  describe('getSuccessPayload', () => {
    it('returns response data', () => {
      const response = { data: 'data' };
      assert.deepEqual(axiosDriver.getSuccessPayload(response), response.data);
    });

    it('returns array of response data', () => {
      const responses = [{ data: 'data1' }, { data: 'data2' }];
      assert.deepEqual(axiosDriver.getSuccessPayload(responses), [responses[0].data, responses[1].data]);
    });
  });

  describe('getErrorPayload', () => {
    it('returns error', () => {
      const error = 'error';
      assert.equal(axiosDriver.getErrorPayload(error), error);
    });
  });

  describe('getRequestHandlers', () => {
    // TODO: add sinon mock
    it.skip('returns request handlers', () => {
      const tokenSource = axios.CancelToken.source();
      const requestInstance = { type: 'axios' };
      const expected = {
        sendRequest: requestConfig => call(requestInstance, { cancelToken: tokenSource.token, ...requestConfig }),
        abortRequest: call([tokenSource, 'cancel']),
      };
      assert.deepEqual(axiosDriver.getRequestHandlers(requestInstance).sendRequest, expected.sendRequest);
    });<commit_msg>Finished getRequestHandlers test<commit_after>import sinon from 'sinon';
import axios from 'axios';
import { call } from 'redux-saga/effects';

import axiosDriver from './axios-driver';

describe('axios driver', () => {
  describe('getSuccessPayload', () => {
    it('returns response data', () => {
      const response = { data: 'data' };
      assert.deepEqual(axiosDriver.getSuccessPayload(response), response.data);
    });

    it('returns array of response data', () => {
      const responses = [{ data: 'data1' }, { data: 'data2' }];
      assert.deepEqual(axiosDriver.getSuccessPayload(responses), [responses[0].data, responses[1].data]);
    });
  });

  describe('getErrorPayload', () => {
    it('returns error', () => {
      const error = 'error';
      assert.equal(axiosDriver.getErrorPayload(error), error);
    });
  });

  describe('getRequestHandlers', () => {
    after(() => {
      axios.CancelToken.source.restore();
    });

    it('returns request handlers', () => {
      const tokenSource = {
        token: 'token',
        cancel: () => {},
      };

      sinon.stub(axios.CancelToken, 'source').returns(tokenSource);
      const config = { myKey: 'myValue' };
      const requestInstance = () => {};
      const expected = {
        sendRequest: requestConfig => call(requestInstance, { cancelToken: tokenSource.token, ...requestConfig }),
        abortRequest: call([tokenSource, 'cancel']),
      };
      const result = axiosDriver.getRequestHandlers(requestInstance);
      assert.hasAllKeys(result, ['sendRequest', 'abortRequest']);
      assert.deepEqual(result.abortRequest, expected.abortRequest);
      assert.deepEqual(result.sendRequest(config), expected.sendRequest(config));
    });
{'fraction_non_alphanumeric': 0.16868257600523046, 'fraction_numerical': 0.002615233736515201, 'mean_word_length': 3.5671641791044775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '4311139', 'n_tokens_mistral': 886, 'n_tokens_neox': 879, 'n_words': 166}