<commit_before>(function(describe){
    "use strict";
    describe("Facility view controllers test suite", function(){
        var createController, $scope, $stateParams, $httpBackend, $state;
        var formService, SERVER_URL, facilityApi;
        var errorRes = {
            error:{error_msg:{error: "error"}}
        };
        beforeEach(function(){
            module("mflAdminApp");
            inject(["$rootScope", "$controller", "$stateParams", "$httpBackend",
                   "$state","mfl.common.forms.changes","SERVER_URL","mfl.facilities.wrappers",
                   function($rootScope, $controller,_$stateParams,
                    _$httpBackend, _$state, frm, _SERVER_URL, _facilityApi){
                $scope = $rootScope.$new();
                facilityApi = _facilityApi;
                SERVER_URL = _SERVER_URL;
                $httpBackend = _$httpBackend;
                $stateParams = _$stateParams;
                $state = _$state;
                formService = frm;
                var data = {
                    $scope: $scope
                };
                createController = function(ctrl, params){
                    return $controller(ctrl, _.extend(data, params));

                };
            }]);
        });

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

        it("should have `mfl.facilities.controllers.view.base` defined",
           function(){
                var dt = {
                    $stateParams: {facilityId: 1}
                };
                var ctrl = createController("mfl.facilities.controllers.view.base", dt);
                expect(ctrl).toBeDefined();
            });

        it("should retrieve a facility : fail ", function(){
            var dt = {
                    $stateParams: {facilityId: 1}
                };
            $httpBackend.expectGET(SERVER_URL+"api/facilities/facilities/1/")
            .respond(500, errorRes);
            createController("mfl.facilities.controllers.view.base", dt);
            $httpBackend.flush();
            expect($scope.alert).toBeTruthy();
        });

        it("should retrieve a facility : success ", function(){
            var dt = {
                    $stateParams: {facilityId: 1}
                };
            var res = {name: "KNHH"};
            $httpBackend.expectGET(SERVER_URL+"api/facilities/facilities/1/")
            .respond(200, res);
            createController("mfl.facilities.controllers.view.base", dt);
            $httpBackend.flush();
            expect($scope.facility).toEqual(res);
        });

        it("should have mfl.facilities.controllers.view.approve` defined",
           function(){
                var dt = {
                    $stateParams: {facilityId: 1}
                };
                var ctrl = createController("mfl.facilities.controllers.view.approve", dt);
                expect(ctrl).toBeDefined();
            });
        it("should approve facility: success",
           function(){
                var dt = {
                    $stateParams: {facilityId: 1}
                };
                var res = {name: "KNHH"};
                $httpBackend.expectGET(SERVER_URL+"api/facilities/facilities/1/")
                .respond(200, res);
                $httpBackend.expectGET(SERVER_URL+"api/facilities/facilitiy_approvals/?facility=1")
                .respond(200, res);
                $httpBackend.expectPOST(SERVER_URL+"api/facilities/facilitiy_approvals/")
                .respond(200, {msg: "ok"});
                createController("mfl.facilities.controllers.view.approve", dt);
                $scope.approveFacility(res);
                $httpBackend.flush();
                expect($scope.facility_approvals).toEqual(res);

            });

        it("should approve facility: success",
           function(){
                var dt = {
                    $stateParams: {facilityId: 1}
                };
                var res = {name: "KNHH"};
                $httpBackend.expectGET(SERVER_URL+"api/facilities/facilities/1/")
                .respond(200, res);
                $httpBackend.expectGET(SERVER_URL+"api/facilities/facilitiy_approvals/?facility=1")
                .respond(200, res);
                $httpBackend.expectPOST(SERVER_URL+"api/facilities/facilitiy_approvals/")
                .respond(500, errorRes);
                createController("mfl.facilities.controllers.view.approve", dt);
                $scope.approveFacility(res);
                $httpBackend.flush();
                expect($scope.alert).toBeDefined();

            });

    });
})(describe);<commit_msg>tests for adding facility unit<commit_after>(function(describe){
    "use strict";
    describe("Facility view controllers test suite", function(){
        var createController, $scope, $stateParams, $httpBackend, $state;
        var formService, SERVER_URL, facilityApi;
        var errorRes = {
            error:{error_msg:{error: "error"}}
        };
        var testFunc = {callback: function(){}};
        beforeEach(function(){
            module("mflAdminApp");
            inject(["$rootScope", "$controller", "$stateParams", "$httpBackend",
                   "$state","mfl.common.forms.changes","SERVER_URL","mfl.facilities.wrappers",
                   function($rootScope, $controller,_$stateParams,
                    _$httpBackend, _$state, frm, _SERVER_URL, _facilityApi){
                $scope = $rootScope.$new();
                facilityApi = _facilityApi;
                SERVER_URL = _SERVER_URL;
                $httpBackend = _$httpBackend;
                $stateParams = _$stateParams;
                $state = _$state;
                formService = frm;
                var data = {
                    $scope: $scope
                };
                createController = function(ctrl, params){
                    return $controller(ctrl, _.extend(data, params));

                };
            }]);
        });

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

        it("should have `mfl.facilities.controllers.view.base` defined",
           function(){
                var dt = {
                    $stateParams: {facilityId: 1}
                };
                var ctrl = createController("mfl.facilities.controllers.view.base", dt);
                expect(ctrl).toBeDefined();
            });

        it("should retrieve a facility : fail ", function(){
            var dt = {
                    $stateParams: {facilityId: 1}
                };
            $httpBackend.expectGET(SERVER_URL+"api/facilities/facilities/1/")
            .respond(500, errorRes);
            createController("mfl.facilities.controllers.view.base", dt);
            $httpBackend.flush();
            expect($scope.alert).toBeTruthy();
        });

        it("should retrieve a facility : success ", function(){
            var dt = {
                    $stateParams: {facilityId: 1}
                };
            var res = {name: "KNHH"};
            $httpBackend.expectGET(SERVER_URL+"api/facilities/facilities/1/")
            .respond(200, res);
            createController("mfl.facilities.controllers.view.base", dt);
            $httpBackend.flush();
            expect($scope.facility).toEqual(res);
        });

        it("should have mfl.facilities.controllers.view.approve` defined",
           function(){
                var dt = {
                    $stateParams: {facilityId: 1}
                };
                var ctrl = createController("mfl.facilities.controllers.view.approve", dt);
                expect(ctrl).toBeDefined();
            });
        it("should approve facility: success",
           function(){
                var dt = {
                    $stateParams: {facilityId: 1}
                };
                var res = {name: "KNHH"};
                $httpBackend.expectGET(SERVER_URL+"api/facilities/facilities/1/")
                .respond(200, res);
                $httpBackend.expectGET(SERVER_URL+"api/facilities/facilitiy_approvals/?facility=1")
                .respond(200, res);
                $httpBackend.expectPOST(SERVER_URL+"api/facilities/facilitiy_approvals/")
                .respond(200, {msg: "ok"});
                createController("mfl.facilities.controllers.view.approve", dt);
                $scope.approveFacility(res);
                $httpBackend.flush();
                expect($scope.facility_approvals).toEqual(res);

            });

        it("should approve facility: fail",
           function(){
                var dt = {
                    $stateParams: {facilityId: 1}
                };
                var res = {name: "KNHH"};
                $httpBackend.expectGET(SERVER_URL+"api/facilities/facilities/1/")
                .respond(200, res);
                $httpBackend.expectGET(SERVER_URL+"api/facilities/facilitiy_approvals/?facility=1")
                .respond(200, res);
                $httpBackend.expectPOST(SERVER_URL+"api/facilities/facilitiy_approvals/")
                .respond(500, errorRes);
                createController("mfl.facilities.controllers.view.approve", dt);
                $scope.approveFacility(res);
                $httpBackend.flush();
                expect($scope.alert).toBeDefined();

            });

        it("should have mfl.facilities.controllers.view.add_unit` defined",
           function(){
                var dt = {
                    $stateParams: {facilityId: 1}
                };
                var ctrl = createController("mfl.facilities.controllers.view.add_unit", dt);
                expect(ctrl).toBeDefined();
            });
        it("should add facility unit: success",
           function(){
                var dt = {
                    $stateParams: {facilityId: 1}
                };
                var res = {name: "KNHH"};
                $httpBackend.expectGET(SERVER_URL+"api/facilities/facilities/1/")
                .respond(200, res);
                $httpBackend.expectGET(SERVER_URL+"api/facilities/facility_units/?facility=1")
                .respond(200, res);
                $httpBackend.expectPOST(SERVER_URL+"api/facilities/facility_units/")
                .respond(200, {msg: "ok"});
                createController("mfl.facilities.controllers.view.add_unit", dt);
                $scope.saveFacilityUnit(res);
                $httpBackend.flush();
                expect($scope.facility_units).toEqual(res);

            });

        it("should add  facility unit: fail",function(){
                var dt = {
                    $stateParams: {facilityId: 1}
                };
                var res = {name: "KNHH"};
                $httpBackend.expectGET(SERVER_URL+"api/facilities/facilities/1/")
                .respond(200, res);
                $httpBackend.expectGET(SERVER_URL+"api/facilities/facility_units/?facility=1")
                .respond(200, res);
                $httpBackend.expectPOST(SERVER_URL+"api/facilities/facility_units/")
                .respond(500, errorRes);
                createController("mfl.facilities.controllers.view.add_unit", dt);
                $scope.saveFacilityUnit(res);
                $httpBackend.flush();
                expect($scope.alert).toBeDefined();
            });

        it("should get options data, `regulatory body` in facility unit: success ", function(){
            spyOn(testFunc, "callback");
            var dt = {
                $stateParams: {facilityId: 1}
            };
            var res = {results: {name: "KNHH"}};

            $httpBackend.expectGET(SERVER_URL+"api/facilities/regulating_bodies/")
            .respond(200, res);
            createController("mfl.facilities.controllers.view.add_unit", dt);
            $scope.getOptionsData.regulatingBody(testFunc.callback);
            $httpBackend.flush();
            expect(testFunc.callback).toHaveBeenCalledWith(res.results);
        });

        it("should get options data, `regulatory body` in facility unit: fail ", function(){
            spyOn(testFunc, "callback");
            var dt = {
                $stateParams: {facilityId: 1}
            };

            $httpBackend.expectGET(SERVER_URL+"api/facilities/regulating_bodies/")
            .respond(500, errorRes);
            createController("mfl.facilities.controllers.view.add_unit", dt);
            $scope.getOptionsData.regulatingBody(testFunc.callback);
            $httpBackend.flush();
            expect($scope.alert).toBeDefined();
        });

        it("should get options data, `regulation status` in facility unit: success ", function(){
            spyOn(testFunc, "callback");
            var dt = {
                $stateParams: {facilityId: 1}
            };
            var res = {results: {name: "KNHH"}};

            $httpBackend.expectGET(SERVER_URL+"api/facilities/regulation_status/")
            .respond(200, res);
            createController("mfl.facilities.controllers.view.add_unit", dt);
            $scope.getOptionsData.regulationStatus(testFunc.callback);
            $httpBackend.flush();
            expect(testFunc.callback).toHaveBeenCalledWith(res.results);
        });

    });
})(describe);
{'fraction_non_alphanumeric': 0.12792100105532941, 'fraction_numerical': 0.008216493291120158, 'mean_word_length': 1.689438475572674, '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': '3953438', 'n_tokens_mistral': 3694, 'n_tokens_neox': 3455, 'n_words': 552}