<commit_before>
    describe("Test lux.webapi module", function() {
        var context = {
            API_URL: '/api'
        },
        $lux,
        scope,
        $httpBackend;

        angular.module('lux.webapi.test', ['lux.loader', 'lux.restapi', 'lux.restapi.mock'])
            .value('context', context);

        beforeEach(function() {
            module('lux.webapi.test');

            inject(['$lux', '$rootScope', '$httpBackend', function (_$lux_, _$rootScope_, _$httpBackend_) {
                $lux = _$lux_;
                scope = _$rootScope_;
                $httpBackend = _$httpBackend_;
            }]);
        });

        it("formReady should stringify json array", function() {
            var client = scope.api(),
                mock_data = {
                    'jsonArrayField': [1,2,3]
                };

            var model = {},
                formScope = {
                    formModelName: 'TestForm',
                    TestFormType: {
                        jsonArrayField: 'json'
                    }
                };

            $httpBackend.expectGET('').respond(mock_data);
            client.defaults().get = true;
            client.formReady(model, formScope);
            $httpBackend.flush();

            expect(typeof model.jsonArrayField).toBe('string');
        });

        it("formReady should set a set array of items", function() {
            var client = scope.api(),
                mock_data = {
                    arrayField: [1,2,3],
                    arrayObjectField: [
                        {id: 5},
                        {id: 6}
                    ]
                };

            var model = {},
                formScope = {
                    formModelName: 'TestForm',
                    TestFormType: {}
                };

            $httpBackend.expectGET('').respond(mock_data);
            client.defaults().get = true;
            client.formReady(model, formScope);
            $httpBackend.flush();

            expect(model.arrayField instanceof Array).toBe(true);
            expect(model.arrayObjectField[0]).toBe(5);
            expect(model.arrayObjectField[1]).toBe(6);
        });

        it("formReady should set string value", function() {
            var client = scope.api(),
                mock_data = {
                    stringField: 'testString',
                    objectField: {id: 'testString'}
                };

            var model = {},
                formScope = {
                    formModelName: 'TestForm',
                    TestFormType: {}
                };

            $httpBackend.expectGET('').respond(mock_data);
            client.defaults().get = true;
            client.formReady(model, formScope);
            $httpBackend.flush();

            expect(model.stringField).toBe('testString');
            expect(model.objectField).toBe('testString');
        });
    });<commit_msg>add tests for default js api params<commit_after>describe("Test lux.webapi module", function () {
    var context = {
            API_URL: '/api'
        },
        $lux,
        scope,
        $httpBackend;

    angular.module('lux.webapi.test', ['lux.loader', 'lux.restapi', 'lux.restapi.mock'])
        .value('context', context);

    beforeEach(function () {
        module('lux.webapi.test');

        inject(['$lux', '$rootScope', '$httpBackend', function (_$lux_, _$rootScope_, _$httpBackend_) {
            $lux = _$lux_;
            scope = _$rootScope_;
            $httpBackend = _$httpBackend_;
        }]);
    });

    afterEach(function () {
        $httpBackend.verifyNoOutstandingExpectation();
        $httpBackend.verifyNoOutstandingRequest();
    });

    it("uses default parameters for GETs", function () {
        var client = $lux.api({
            url: context.API_URL,
            params: {
                defaultParam: 'defaultValue'
            }
        });

        $httpBackend.expectGET('/api?defaultParam=defaultValue&param=value').respond('');

        client.get('/', {param: 'value'});
        expect($httpBackend.flush).not.toThrow();
    });

    it("works without default parameters for GETs", function () {
        var client = $lux.api({
            url: context.API_URL
        });

        $httpBackend.expectGET('/api?param=value').respond('');

        client.get('/', {param: 'value'});
        expect($httpBackend.flush).not.toThrow();
    });

    it("formReady should stringify json array", function () {
        var client = scope.api(),
            mock_data = {
                'jsonArrayField': [1, 2, 3]
            };

        var model = {},
            formScope = {
                formModelName: 'TestForm',
                TestFormType: {
                    jsonArrayField: 'json'
                }
            };

        $httpBackend.expectGET('').respond(mock_data);
        client.defaults().get = true;
        client.formReady(model, formScope);
        $httpBackend.flush();

        expect(typeof model.jsonArrayField).toBe('string');
    });

    it("formReady should set a set array of items", function () {
        var client = scope.api(),
            mock_data = {
                arrayField: [1, 2, 3],
                arrayObjectField: [
                    {id: 5},
                    {id: 6}
                ]
            };

        var model = {},
            formScope = {
                formModelName: 'TestForm',
                TestFormType: {}
            };

        $httpBackend.expectGET('').respond(mock_data);
        client.defaults().get = true;
        client.formReady(model, formScope);
        $httpBackend.flush();

        expect(model.arrayField instanceof Array).toBe(true);
        expect(model.arrayObjectField[0]).toBe(5);
        expect(model.arrayObjectField[1]).toBe(6);
    });

    it("formReady should set string value", function () {
        var client = scope.api(),
            mock_data = {
                stringField: 'testString',
                objectField: {id: 'testString'}
            };

        var model = {},
            formScope = {
                formModelName: 'TestForm',
                TestFormType: {}
            };

        $httpBackend.expectGET('').respond(mock_data);
        client.defaults().get = true;
        client.formReady(model, formScope);
        $httpBackend.flush();

        expect(model.stringField).toBe('testString');
        expect(model.objectField).toBe('testString');
    });
});
{'fraction_non_alphanumeric': 0.1373880827415869, 'fraction_numerical': 0.003704847175054029, 'mean_word_length': 1.532838154808444, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1338644', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1670, 'n_words': 302}