import './index';

describe('Client', () => {
    describe('Component vnClientCreditInsuranceCreate', () => {
        let controller;
        let $scope;
        let $httpBackend;

        beforeEach(ngModule('client'));

        beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
            $httpBackend = _$httpBackend_;
            $scope = $rootScope.$new();
            $scope.form = {
                $invalid: false
            };
            const $element = angular.element('<vn-client-credit-insurance-create></vn-client-credit-insurance-create>');
            controller = $componentController('vnClientCreditInsuranceCreate', {$element, $scope});
            controller.client = {id: 1101};
            controller.card = {
                reload: () => {}
            };
        }));

        describe('onSubmit()', () => {
            it('should perform a POST query', () => {
                let started = new Date();
                controller.creditClassification = {
                    started: started,
                    credit: 300,
                    grade: 1
                };

                let newData = {
                    started: started,
                    credit: 300,
                    grade: 1,
                    clientFk: 1101
                };

                $httpBackend.whenPOST(`creditClassifications/createWithInsurance`, newData).respond(200, true);
                $httpBackend.expectPOST(`creditClassifications/createWithInsurance`, newData);
                controller.onSubmit();
                $httpBackend.flush();
            });
        });
    });
});