<commit_before>/*
  eslint-disable prefer-arrow-callback,
  func-names,
  space-before-function-paren,
  no-unused-expressions
*/
import chai, { expect } from 'chai';
import { actions, DEFAULT_POLLING_INTERVAL } from '../../constants';
import {
  startPolling,
  stopPolling,
  setPollingInterval,
  setPollUrl,
  assignWork,
  captchaRequired,
  iconClicked,
} from '../../actions';
import chaiImmutable from 'chai-immutable';
import polling from '../polling';

chai.use(chaiImmutable);

const checkState = (state) => {
  expect(state).to.have.keys(['polling', 'pollUrl', 'error', 'interval', 'captchaRequired']);
};

const initState = polling(undefined, { type: 'INIT' });

describe('polling reducer', function() {
  it('starts without polling', function() {
    const state = initState;
    checkState(initState);
    expect(state.get('polling')).to.be.false;
    expect(state.get('pollUrl')).to.be.null;
    expect(state.get('interval')).to.equal(DEFAULT_POLLING_INTERVAL);
  });

  describe(actions.START_POLLING, function() {
    it('sets the polling params', function() {
      const url = 'http://example.com';
      const state = polling(undefined, startPolling({ url }));
      checkState(state);

      expect(state.get('polling')).to.be.true;
      expect(state.get('pollUrl')).to.equal(url);
    });

    describe('without a URL', function() {
      it('sets the polling param', function() {
        const state = polling(initState, startPolling());
        checkState(state);

        expect(state.get('polling')).to.be.true;
        expect(state.get('pollUrl')).to.be.null;
        expect(state.get('error')).to.be.null;
      });
    });
  });

  describe(actions.STOP_POLLING, function() {
    it('sets the polling params', function() {
      let state = polling(undefined, startPolling({ url: 'http://example.com' }));
      checkState(state);
      state = polling(state, stopPolling());
      checkState(state);

      expect(state.get('polling')).to.be.false;
      expect(state.get('pollUrl')).to.equal('http://example.com');
    });
  });

  describe(actions.SET_POLLING_INTERVAL, function() {
    it('sets the polling interval', function() {
      const state = polling(undefined, setPollingInterval(42));
      checkState(state);

      expect(state.get('interval')).to.equal(42);
    });
  });

  describe(actions.SET_POLL_URL, function() {
    it('sets the URL for polling', function() {
      const state = polling(undefined, setPollUrl('http://work.com'));
      checkState(state);

      expect(state.get('pollUrl')).to.equal('http://work.com');
    });
  });

  describe(actions.ASSIGN_WORK, function() {
    it('stops polling', function() {
      let state = polling(undefined, startPolling({ url: 'http://example.com' }));
      checkState(state);
      state = polling(state, assignWork({ url: 'http://work.com' }));
      checkState(state);

      expect(state.get('polling')).to.be.false;
    });
  });

  describe(actions.CAPTCHA_REQUIRED, function() {
    it('sets captchaRequired to true', function() {
      let state = initState;
      state = polling(state, startPolling({ url: 'http://example.com' }));
      state = polling(state, captchaRequired());
      checkState(state);

      expect(state.get('captchaRequired')).to.be.true;
    });
  });

  describe(actions.ICON_CLICKED, function() {
    it('sets captchaRequired to false', function() {
      let state = initState;
      state = polling(state, startPolling({ url: 'http://example.com' }));
      state = polling(state, captchaRequired());
      state = polling(state, iconClicked());
      checkState(state);

      expect(state.get('captchaRequired')).to.be.false;
    });
  });
});<commit_msg>reducer test for RATE_LIMIT_EXCEEDED<commit_after>/*
  eslint-disable prefer-arrow-callback,
  func-names,
  space-before-function-paren,
  no-unused-expressions
*/
import chai, { expect } from 'chai';
import { actions, DEFAULT_POLLING_INTERVAL } from '../../constants';
import {
  startPolling,
  stopPolling,
  setPollingInterval,
  setPollUrl,
  assignWork,
  captchaRequired,
  iconClicked,
  rateLimitExceeded,
} from '../../actions';
import chaiImmutable from 'chai-immutable';
import polling from '../polling';

chai.use(chaiImmutable);

const checkState = (state) => {
  expect(state).to.have.keys(['polling', 'pollUrl', 'error', 'interval', 'captchaRequired']);
};

const initState = polling(undefined, { type: 'INIT' });

describe('polling reducer', function() {
  it('starts without polling', function() {
    const state = initState;
    checkState(initState);
    expect(state.get('polling')).to.be.false;
    expect(state.get('pollUrl')).to.be.null;
    expect(state.get('interval')).to.equal(DEFAULT_POLLING_INTERVAL);
  });

  describe(actions.START_POLLING, function() {
    it('sets the polling params', function() {
      const url = 'http://example.com';
      const state = polling(undefined, startPolling({ url }));
      checkState(state);

      expect(state.get('polling')).to.be.true;
      expect(state.get('pollUrl')).to.equal(url);
    });

    describe('without a URL', function() {
      it('sets the polling param', function() {
        const state = polling(initState, startPolling());
        checkState(state);

        expect(state.get('polling')).to.be.true;
        expect(state.get('pollUrl')).to.be.null;
        expect(state.get('error')).to.be.null;
      });
    });
  });

  describe(actions.STOP_POLLING, function() {
    it('sets the polling params', function() {
      let state = polling(undefined, startPolling({ url: 'http://example.com' }));
      checkState(state);
      state = polling(state, stopPolling());
      checkState(state);

      expect(state.get('polling')).to.be.false;
      expect(state.get('pollUrl')).to.equal('http://example.com');
    });
  });

  describe(actions.SET_POLLING_INTERVAL, function() {
    it('sets the polling interval', function() {
      const state = polling(undefined, setPollingInterval(42));
      checkState(state);

      expect(state.get('interval')).to.equal(42);
    });
  });

  describe(actions.SET_POLL_URL, function() {
    it('sets the URL for polling', function() {
      const state = polling(undefined, setPollUrl('http://work.com'));
      checkState(state);

      expect(state.get('pollUrl')).to.equal('http://work.com');
    });
  });

  describe(actions.ASSIGN_WORK, function() {
    it('stops polling', function() {
      let state = polling(undefined, startPolling({ url: 'http://example.com' }));
      checkState(state);
      state = polling(state, assignWork({ url: 'http://work.com' }));
      checkState(state);

      expect(state.get('polling')).to.be.false;
    });
  });

  describe(actions.CAPTCHA_REQUIRED, function() {
    it('sets captchaRequired to true', function() {
      let state = initState;
      state = polling(state, startPolling({ url: 'http://example.com' }));
      state = polling(state, captchaRequired());
      checkState(state);

      expect(state.get('captchaRequired')).to.be.true;
    });
  });

  describe(actions.ICON_CLICKED, function() {
    it('sets captchaRequired to false', function() {
      let state = initState;
      state = polling(state, startPolling({ url: 'http://example.com' }));
      state = polling(state, captchaRequired());
      state = polling(state, iconClicked());
      checkState(state);

      expect(state.get('captchaRequired')).to.be.false;
    });
  });
  
  describe(actions.RATE_LIMIT_EXCEEDED, function() {
    it('increases polling Interval when rate limit exceeded', function() {
      let state = polling(undefined, setPollingInterval(30));
      checkState(state);
      state = polling(state, rateLimitExceeded());
      checkState(state);
      
      expect(state.get('interval')).to.equal(33);
    });
  });  
});
{'fraction_non_alphanumeric': 0.17492636701242156, 'fraction_numerical': 0.001536688436419516, 'mean_word_length': 3.575278265963679, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '799781', 'n_tokens_mistral': 2505, 'n_tokens_neox': 2441, 'n_words': 436}