<commit_before>/*jshint ignore:start */
'use strict';

describe('Data.timetables', function() {
    var rewire = require('rewire');
    var data, fetch, status, ret_json, last_url, last_options;

    beforeEach(function() {
        data = rewire('../index');
        data.__set__('fetch', function fetch(url, options) {
            last_url = url;
            last_options = options;
            return new Promise(res => {
                res({
                    status: status,
                    statusText: 'Dummy status text',
                    json: () => {
                        return new Promise(_res => _res(ret_json));
                    }
                });
            });
        });
    });

    it('should not allow .getForClass with empty class name', function(done) {
        status = 200;
        ret_json = { dummy: 'json' };

        data.timetables.getForClass().then(() => {
            done.fail('.getForClass allowed empty class name');
        }).catch(() => done());
    });

    it('should make a request without a cursor when .getAll is not given a cursor', function() {
        status = 200;
        ret_json = { dummy: 'json' };

        data.timetables.getAll();

        expect(last_url).toEqual('/api/timetables/all');
    });

    it('should make a request with a cursor when .getAll is given a cursor', function() {
        status = 200;
        ret_json = { dummy: 'json' };

        var cursor = 'dummy_cursor_21424';

        data.timetables.getAll(cursor);

        expect(last_url).toEqual('/api/timetables/all?cursor=' + cursor);
    });

    it('should fail when .getForClass receives a non-200 response', function(done) {
        status = 400;
        ret_json = { dummy: 'json' };

        data.timetables.getForClass('nil').then(() => {
            done.fail('.getForClass didn\'t fail on non-200 response');
        }).catch(err => { done(); });
    });
    it('should fail when .getAll receives a non-200 response', function(done) {
        status = 400;
        ret_json = { dummy: 'json' };

        data.timetables.getAll().then(() => {
            done.fail('.getAll didn\'t fail on non-200 response');
        }).catch(err => { done(); });
    });

    it('should submit the data of .input verbatim as JSON', function(done) {
        status = 200;
        ret_json = { dummy: 'json' };<commit_msg>Fix tests<commit_after>/*jshint ignore:start */
'use strict';

describe('Data.timetables', function() {
    var rewire = require('rewire');
    var data, fetch, status, ret_json, last_url, last_options;

    beforeEach(function() {
        data = rewire('../index');
        data.__set__('fetch', function fetch(url, options) {
            last_url = url;
            last_options = options;
            return new Promise(res => {
                res({
                    status: status,
                    statusText: 'Dummy status text',
                    json: () => {
                        return new Promise(_res => _res(ret_json));
                    }
                });
            });
        });
    });

    it('should not allow .getForClass with empty class name', function(done) {
        status = 200;
        ret_json = { dummy: 'json' };

        data.timetables.getForClass().then(() => {
            done.fail('.getForClass allowed empty class name');
        }).catch(() => done());
    });

    it('should make a request without a cursor when .getAll is not given a cursor', function() {
        status = 200;
        ret_json = { dummy: 'json' };

        data.timetables.getAll();

        expect(last_url).toEqual('/admin/api/timetables/all');
    });

    it('should make a request with a cursor when .getAll is given a cursor', function() {
        status = 200;
        ret_json = { dummy: 'json' };

        var cursor = 'dummy_cursor_21424';

        data.timetables.getAll(cursor);

        expect(last_url).toEqual('/admin/api/timetables/all?cursor=' + cursor);
    });

    it('should fail when .getForClass receives a non-200 response', function(done) {
        status = 400;
        ret_json = { dummy: 'json' };

        data.timetables.getForClass('nil').then(() => {
            done.fail('.getForClass didn\'t fail on non-200 response');
        }).catch(err => { done(); });
    });
    it('should fail when .getAll receives a non-200 response', function(done) {
        status = 400;
        ret_json = { dummy: 'json' };

        data.timetables.getAll().then(() => {
            done.fail('.getAll didn\'t fail on non-200 response');
        }).catch(err => { done(); });
    });

    it('should submit the data of .input verbatim as JSON', function(done) {
        status = 200;
        ret_json = { dummy: 'json' };
{'fraction_non_alphanumeric': 0.14980956411341514, 'fraction_numerical': 0.014811680067710538, 'mean_word_length': 1.9767002518891688, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '3399148', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1319, 'n_words': 345}