front & back tests

This commit is contained in:
Joan Sanchez 2018-08-09 12:54:29 +02:00
parent 3478d50b43
commit f15d8c3087
6 changed files with 95 additions and 5 deletions

View File

@ -25,8 +25,7 @@ describe('Client', () => {
};
}
};
$httpBackend.get = jasmine.createSpy('get').and.returnValue(Promise.resolve());
controller = $componentController('vnClientBillingData', {$scope: $scope}, {$http: $httpBackend});
controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.client = {id: 101, name: 'Client name', payMethodFk: 4};
}));
@ -47,6 +46,15 @@ describe('Client', () => {
});
});
describe('notifyChanges()', () => {
it(`should call notifyChanges() and perform a GET query`, () => {
$httpBackend.when('GET', `/mailer/notification/payment-update/101`).respond(true);
$httpBackend.expect('GET', `/mailer/notification/payment-update/101`);
controller.notifyChanges();
$httpBackend.flush();
});
});
describe('hasPaymethodChanged()', () => {
it(`should call hasPaymethodChanged() and return true if there are changes on payMethod data`, () => {
controller.client.payMethodFk = 5;

View File

@ -1,4 +1,4 @@
<form name="form" ng-submit="$ctrl.submit()">
<form name="form" ng-submit="$ctrl.onSubmit()">
<vn-card pad-large>
<vn-title>New contract</vn-title>
<vn-horizontal>

View File

@ -12,7 +12,7 @@ class Controller {
};
}
submit() {
onSubmit() {
if (this.$scope.form.$invalid)
return this.vnApp.showError(this.$translate.instant('Some fields are invalid'));

View File

@ -0,0 +1,51 @@
import './index';
describe('Client', () => {
describe('Component vnClientCreditInsuranceCreate', () => {
let $componentController;
let controller;
let $scope;
let $httpBackend;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new();
$scope.form = {
$invalid: false
};
controller = $componentController('vnClientCreditInsuranceCreate', {$scope: $scope});
controller.client = {id: 101};
controller.card = {
reload: () => {}
};
}));
describe('onSubmit()', () => {
it('should perform a POST query', () => {
controller.creditClassification = {
started: new Date(),
credit: 300,
grade: 1
};
let newData = {
started: new Date(),
credit: 300,
grade: 1,
clientFk: 101
};
$httpBackend.whenPOST(`/client/api/creditClassifications/createWithInsurance`, newData).respond(200, true);
$httpBackend.expectPOST(`/client/api/creditClassifications/createWithInsurance`, newData);
controller.onSubmit();
$httpBackend.flush();
});
});
});
});

View File

@ -1,6 +1,6 @@
import './index';
describe('Client', () => {
fdescribe('Client', () => {
describe('Component vnClientCreditInsuranceIndex', () => {
let $componentController;
let controller;
@ -15,6 +15,7 @@ describe('Client', () => {
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnClientCreditInsuranceIndex');
controller.client = {id: 101};
}));
describe('_getClassifications()', () => {
@ -73,5 +74,18 @@ describe('Client', () => {
expect(controller.$scope.closeContract.show).toHaveBeenCalledWith();
});
});
describe('returnDialog()', () => {
it('should call the returnDialog method and perform a PATCH query, then call _getClassifications method', () => {
spyOn(controller, '_getClassifications');
controller.classificationId = 1;
$httpBackend.when('PATCH', `/client/api/CreditClassifications/1`).respond(200);
$httpBackend.expect('PATCH', `/client/api/CreditClassifications/1`);
controller.returnDialog('ACCEPT');
$httpBackend.flush();
expect(controller._getClassifications).toHaveBeenCalledWith(101);
});
});
});
});

View File

@ -0,0 +1,17 @@
const app = require(`../../../../server/server`);
describe('order itemFilter()', () => {
it('should call the itemFilter method and return an array of items', async() => {
let filter = {
where: {
id: 1,
typeFk: 1
}
};
let result = await app.models.Order.itemFilter(filter);
let firstItemId = result[0].item_id;
expect(result.length).toEqual(2);
expect(firstItemId).toEqual(3);
});
});