<commit_before>import proxyquire from 'proxyquire';
import actions from './../../actions/challenges';

describe('component/challengeList', () => {
    const mockChallenges = [1, 2, 3];

    let sut,
        challengeList,
        connector,
        dispatch,
        mockFetchResponse,
        fakeServerResponse;

    beforeEach(() => {
        dispatch = env.spy();
        connector = env.spy((component) => component);
        const connect = env.stub().returns(connector);
        challengeList = proxyquire('./ChallengeList', {
            'react-redux': {
                connect
            }
        }).default;

        fakeServerResponse = {
            json: env.spy()
        };

        mockFetchResponse = {
            then(fakeCallback) {
                fakeCallback(fakeServerResponse);
                return {
                    then(cb) {
                        cb(mockChallenges);
                    }
                };
            }
        };

        global.fetch = env.spy(() => mockFetchResponse);
    });

    describe('no challenges', () => {
        beforeEach(() => {
            const testState = {
                challenges: [],
                dispatch
            };

            sut = new challengeList(testState);
        });

        it('should call async action to get initial challenges', () => {
            dispatch.should.been.calledWith(sinon.match.func).and.callCount(1);
        });

        it('should call fetch once with correct URL', () => {
            const asyncAction = dispatch.lastCall.args[0];
            asyncAction(dispatch);
            global.fetch.should.been.calledWith('/api/challenges').and.callCount(1);
        });

        it('should convert response to JSON', () => {
            const asyncAction = dispatch.lastCall.args[0];
            asyncAction(dispatch);
            const checkFakeServerResponse = () => fakeServerResponse.json.should.been.called;
            checkFakeServerResponse();
        });

        it('should call sync action with correct params', () => {
            const asyncAction = dispatch.lastCall.args[0];
            asyncAction(dispatch);
            const dispatchArgs = dispatch.lastCall.args[0];
            dispatchArgs.should.eqls({
                type: actions.getChallenges,
                challenges: mockChallenges
            });
        });
    });

    it('should NOT call async action if there are challenges already', () => {
        const testState = {
            challenges: mockChallenges,
            dispatch
        };
        sut = new challengeList(testState);

        const checkDispatch = () => dispatch.should.not.been.called;
        checkDispatch();
    });

    it('should render something', () => {
        const testState = {
            challenges: mockChallenges,
            dispatch
        };
        sut = new challengeList(testState);

        const component = sut.render();
        sinon.assert.match(component, sinon.match.object);<commit_msg>CI fixes<commit_after>import proxyquire from 'proxyquire';
import actions from './../../actions/challenges';

describe('component/challengeList', () => {
    const mockChallenges = [1, 2, 3];

    let sut,
        ChallengeList,
        connector,
        dispatch,
        mockFetchResponse,
        fakeServerResponse;

    beforeEach(() => {
        dispatch = env.spy();
        connector = env.spy((component) => component);
        const connect = env.stub().returns(connector);
        ChallengeList = proxyquire('./ChallengeList', {
            'react-redux': {
                connect
            }
        }).default;

        fakeServerResponse = {
            json: env.spy()
        };

        mockFetchResponse = {
            then(fakeCallback) {
                fakeCallback(fakeServerResponse);
                return {
                    then(cb) {
                        cb(mockChallenges);
                    }
                };
            }
        };

        global.fetch = env.spy(() => mockFetchResponse);
    });

    describe('no challenges', () => {
        beforeEach(() => {
            const testState = {
                challenges: [],
                dispatch
            };

            sut = new ChallengeList(testState);
        });

        it('should call async action to get initial challenges', () => {
            dispatch.should.been.calledWith(sinon.match.func).and.callCount(1);
        });

        it('should call fetch once with correct URL', () => {
            const asyncAction = dispatch.lastCall.args[0];
            asyncAction(dispatch);
            global.fetch.should.been.calledWith('/api/challenges').and.callCount(1);
        });

        it('should convert response to JSON', () => {
            const asyncAction = dispatch.lastCall.args[0];
            asyncAction(dispatch);
            const checkFakeServerResponse = () => fakeServerResponse.json.should.been.called;
            checkFakeServerResponse();
        });

        it('should call sync action with correct params', () => {
            const asyncAction = dispatch.lastCall.args[0];
            asyncAction(dispatch);
            const dispatchArgs = dispatch.lastCall.args[0];
            dispatchArgs.should.eqls({
                type: actions.getChallenges,
                challenges: mockChallenges
            });
        });
    });

    it('should NOT call async action if there are challenges already', () => {
        const testState = {
            challenges: mockChallenges,
            dispatch
        };
        sut = new ChallengeList(testState);

        const checkDispatch = () => dispatch.should.not.been.called;
        checkDispatch();
    });

    it('should render something', () => {
        const testState = {
            challenges: mockChallenges,
            dispatch
        };
        sut = new ChallengeList(testState);

        const component = sut.render();
        sinon.assert.match(component, sinon.match.object);
{'fraction_non_alphanumeric': 0.12042147516307075, 'fraction_numerical': 0.0030105368790767687, 'mean_word_length': 1.67921146953405, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '3952992', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1453, 'n_words': 296}