<commit_before>"use strict";

describe("recurveMock-$httpProvider", function() {
    var $httpDeferred;
    var $httpProvider;
    var handler;

    beforeEach(function() {
        $invoke(["$httpDeferred", "$httpProvider"], function(httpDeferred, httpProvider) {
            $httpDeferred = httpDeferred;
            $httpProvider = httpProvider;
        });

        handler = $httpProvider.on("GET", "www.a.com");
    });

    it("should be invokable", function() {
        expect($httpProvider).toBeDefined();
        expect(isFunction($httpProvider)).toEqual(false);
        expect($httpProvider.send).toBeDefined();
    });

    describe("send", function() {
        it("should return promise", function() {
            var promise = $httpProvider.send({method: "get"}, $httpDeferred());

            expect(promise).toBeDefined();
            expect(promise.then).toBeDefined();
        });

        it("should return httpDeferred promise", function() {
            var httpDeferred = $httpDeferred();
            var promise = $httpProvider.send({method: "get"}, httpDeferred);

            expect(promise).toBe(httpDeferred.promise);
        });
    });

    describe("on", function() {
        it("should return handler", function() {
            expect(handler).toBeDefined();
            expect(handler.respond).toBeDefined();
            expect(handler.expect).toBeDefined();
            expect(handler.callCount).toBeDefined();
        });

        it("should return same handler for repeated calls for same method and url", function() {
            var handler2 = $httpProvider.on("GET", "www.a.com");
            expect(handler).toBe(handler2);
        });

        it("should handle method parameter as case insensitive", function() {
            var handler2 = $httpProvider.on("get", "www.a.com");
            expect(handler).toBe(handler2);
        });

        // TODO TBD most if not all servers are probably setup to handle case insensitive
        it("should handle url parameter as case sensitive", function() {
            var handler2 = $httpProvider.on("get", "www.A.com");
            expect(handler).not.toBe(handler2);
        });

        it("should return different handler for same url but different method", function() {
            var handler2 = $httpProvider.on("POST", "www.a.com");
            expect(handler).not.toBe(handler2);
        });

        it("should return different handler for different url and method", function() {
            var handler2 = $httpProvider.on("GET", "www.b.com");
            expect(handler).not.toBe(handler2);
        });
    });

    describe("respond", function() {
        var callback;
        var promise;

        beforeEach(function() {
            var httpDeferred = $httpDeferred();
            promise = httpDeferred.promise;

            $httpProvider.send({method: "GET", url: "www.a.com"}, httpDeferred);
            callback = jasmine.createSpy("callback");
        });

        it("should be chainable", function() {
            expect(handler.respond()).toEqual(handler);
        });

        it("should resolve promise on success status code", function() {
            handler.respond({status: 200});
            promise.success(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalled();
        });

        it("should reject promise on error status code", function() {
            handler.respond({status: 400});
            promise.error(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalled();
        });

        it("should resolve promise if no status code", function() {
            handler.respond({});
            promise.success(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalled();
        });

        it("should throw error if no data and no expected count set", function() {
            handler.respond();
            promise.then(callback, callback);

            expect(function() {
                $httpProvider.flush();
                expect(callback).not.toHaveBeenCalled();
            }).toThrow();

            expect(callback).not.toHaveBeenCalled();
        });

        it("should allow response to be changed", function() {
            handler.respond({status: 200});
            handler.respond({status: 400});
            promise.error(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalled();
        });

        it("should allow response to be changed after responded", function() {
            handler.respond({status: 200});
            promise.then(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalled();

            handler.respond({status: 400});

            var httpDeferred = $httpDeferred();
            promise = httpDeferred.promise;

            $httpProvider.send({method: "GET", url: "www.a.com"}, httpDeferred);
            callback = jasmine.createSpy("callback");

            promise.error(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalled();
        });

        it("should return response on success", function() {
            handler.respond({status: 200, data: "a"});
            promise.then(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalledWith({status: 200, data: "a"});
        });

        it("should return response on error", function() {
            handler.respond({status: 400, data: "a"});
            promise.then(null, callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalledWith({status: 400, data: "a"});
        });

        it("should return canceled and status 0 for canceled request", function() {
            promise.then(null, callback);
            promise.cancel();

            $httpProvider.flush();
            expect(callback).toHaveBeenCalledWith({status: 0, canceled: true});
        });
    });

    describe("callCount", function() {
        it("should return number of times handler has been called", function() {
            handler.respond({});

            $httpProvider.send({method: "GET", url: "www.a.com"}, $httpDeferred());
            $httpProvider.send({method: "GET", url: "www.a.com"}, $httpDeferred());

            $httpProvider.flush();
            expect(handler.callCount()).toEqual(2);
        });

        it("should include calls with no response data for expected", function() {
            handler.respond().expect(null, 2);

            $httpProvider.send({method: "GET", url: "www.a.com"}, $httpDeferred());
            $httpProvider.send({method: "GET", url: "www.a.com"}, $httpDeferred());

            $httpProvider.flush();
            expect(handler.callCount()).toEqual(2);<commit_msg>added test for respond default status<commit_after>"use strict";

describe("recurveMock-$httpProvider", function() {
    var $httpDeferred;
    var $httpProvider;
    var handler;

    beforeEach(function() {
        $invoke(["$httpDeferred", "$httpProvider"], function(httpDeferred, httpProvider) {
            $httpDeferred = httpDeferred;
            $httpProvider = httpProvider;
        });

        handler = $httpProvider.on("GET", "www.a.com");
    });

    it("should be invokable", function() {
        expect($httpProvider).toBeDefined();
        expect(isFunction($httpProvider)).toEqual(false);
        expect($httpProvider.send).toBeDefined();
    });

    describe("send", function() {
        it("should return promise", function() {
            var promise = $httpProvider.send({method: "get"}, $httpDeferred());

            expect(promise).toBeDefined();
            expect(promise.then).toBeDefined();
        });

        it("should return httpDeferred promise", function() {
            var httpDeferred = $httpDeferred();
            var promise = $httpProvider.send({method: "get"}, httpDeferred);

            expect(promise).toBe(httpDeferred.promise);
        });
    });

    describe("on", function() {
        it("should return handler", function() {
            expect(handler).toBeDefined();
            expect(handler.respond).toBeDefined();
            expect(handler.expect).toBeDefined();
            expect(handler.callCount).toBeDefined();
        });

        it("should return same handler for repeated calls for same method and url", function() {
            var handler2 = $httpProvider.on("GET", "www.a.com");
            expect(handler).toBe(handler2);
        });

        it("should handle method parameter as case insensitive", function() {
            var handler2 = $httpProvider.on("get", "www.a.com");
            expect(handler).toBe(handler2);
        });

        // TODO TBD most if not all servers are probably setup to handle case insensitive
        it("should handle url parameter as case sensitive", function() {
            var handler2 = $httpProvider.on("get", "www.A.com");
            expect(handler).not.toBe(handler2);
        });

        it("should return different handler for same url but different method", function() {
            var handler2 = $httpProvider.on("POST", "www.a.com");
            expect(handler).not.toBe(handler2);
        });

        it("should return different handler for different url and method", function() {
            var handler2 = $httpProvider.on("GET", "www.b.com");
            expect(handler).not.toBe(handler2);
        });
    });

    describe("respond", function() {
        var callback;
        var promise;

        beforeEach(function() {
            var httpDeferred = $httpDeferred();
            promise = httpDeferred.promise;

            $httpProvider.send({method: "GET", url: "www.a.com"}, httpDeferred);
            callback = jasmine.createSpy("callback");
        });

        it("should be chainable", function() {
            expect(handler.respond()).toEqual(handler);
        });

        it("should resolve promise on success status code", function() {
            handler.respond({status: 200});
            promise.success(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalled();
        });

        it("should reject promise on error status code", function() {
            handler.respond({status: 400});
            promise.error(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalled();
        });

        it("should resolve promise if no status code", function() {
            handler.respond({});
            promise.success(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalled();
        });

        it("should throw error if no data and no expected count set", function() {
            handler.respond();
            promise.then(callback, callback);

            expect(function() {
                $httpProvider.flush();
                expect(callback).not.toHaveBeenCalled();
            }).toThrow();

            expect(callback).not.toHaveBeenCalled();
        });

        it("should allow response to be changed", function() {
            handler.respond({status: 200});
            handler.respond({status: 400});
            promise.error(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalled();
        });

        it("should allow response to be changed after responded", function() {
            handler.respond({status: 200});
            promise.then(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalled();

            handler.respond({status: 400});

            var httpDeferred = $httpDeferred();
            promise = httpDeferred.promise;

            $httpProvider.send({method: "GET", url: "www.a.com"}, httpDeferred);
            callback = jasmine.createSpy("callback");

            promise.error(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalled();
        });

        it("should return response on success", function() {
            handler.respond({status: 200, data: "a"});
            promise.then(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalledWith({status: 200, data: "a"});
        });

        it("should return response on error", function() {
            handler.respond({status: 400, data: "a"});
            promise.then(null, callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalledWith({status: 400, data: "a"});
        });

        it("should return canceled and status 0 for canceled request", function() {
            promise.then(null, callback);
            promise.cancel();

            $httpProvider.flush();
            expect(callback).toHaveBeenCalledWith({status: 0, canceled: true});
        });

        it("should overwrite respond for canceled request", function() {
            handler.respond({status: 400});
            promise.then(null, callback);
            promise.cancel();

            $httpProvider.flush();
            expect(callback).toHaveBeenCalledWith({status: 0, canceled: true});
        });

        it("should default status to 200 if not specified", function() {
            handler.respond({data: "a"});
            promise.then(callback);

            $httpProvider.flush();
            expect(callback).toHaveBeenCalledWith({status: 200, data: "a"});
        });
    });

    describe("callCount", function() {
        it("should return number of times handler has been called", function() {
            handler.respond({});

            $httpProvider.send({method: "GET", url: "www.a.com"}, $httpDeferred());
            $httpProvider.send({method: "GET", url: "www.a.com"}, $httpDeferred());

            $httpProvider.flush();
            expect(handler.callCount()).toEqual(2);
        });

        it("should include calls with no response data for expected", function() {
            handler.respond().expect(null, 2);

            $httpProvider.send({method: "GET", url: "www.a.com"}, $httpDeferred());
            $httpProvider.send({method: "GET", url: "www.a.com"}, $httpDeferred());

            $httpProvider.flush();
            expect(handler.callCount()).toEqual(2);
{'fraction_non_alphanumeric': 0.14400056167942146, 'fraction_numerical': 0.007020992768377449, 'mean_word_length': 2.2218954987559374, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 24, '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': '508108', 'n_tokens_mistral': 3705, 'n_tokens_neox': 3556, 'n_words': 802}