From f15d8c308725393261dfe36146d22270ee42af97 Mon Sep 17 00:00:00 2001 From: Joan Date: Thu, 9 Aug 2018 12:54:29 +0200 Subject: [PATCH] front & back tests --- client/client/src/billing-data/index.spec.js | 12 ++++- .../src/credit-insurance/create/index.html | 2 +- .../src/credit-insurance/create/index.js | 2 +- .../src/credit-insurance/create/index.spec.js | 51 +++++++++++++++++++ .../src/credit-insurance/index/index.spec.js | 16 +++++- .../methods/order/specs/itemFilter.spec.js | 17 +++++++ 6 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 client/client/src/credit-insurance/create/index.spec.js create mode 100644 services/order/common/methods/order/specs/itemFilter.spec.js diff --git a/client/client/src/billing-data/index.spec.js b/client/client/src/billing-data/index.spec.js index 73f196206..a777c28d5 100644 --- a/client/client/src/billing-data/index.spec.js +++ b/client/client/src/billing-data/index.spec.js @@ -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; diff --git a/client/client/src/credit-insurance/create/index.html b/client/client/src/credit-insurance/create/index.html index 38c598601..f4b18be8f 100644 --- a/client/client/src/credit-insurance/create/index.html +++ b/client/client/src/credit-insurance/create/index.html @@ -1,4 +1,4 @@ -
+ New contract diff --git a/client/client/src/credit-insurance/create/index.js b/client/client/src/credit-insurance/create/index.js index f812000ce..861568337 100644 --- a/client/client/src/credit-insurance/create/index.js +++ b/client/client/src/credit-insurance/create/index.js @@ -12,7 +12,7 @@ class Controller { }; } - submit() { + onSubmit() { if (this.$scope.form.$invalid) return this.vnApp.showError(this.$translate.instant('Some fields are invalid')); diff --git a/client/client/src/credit-insurance/create/index.spec.js b/client/client/src/credit-insurance/create/index.spec.js new file mode 100644 index 000000000..56739ba55 --- /dev/null +++ b/client/client/src/credit-insurance/create/index.spec.js @@ -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(); + }); + }); + }); +}); diff --git a/client/client/src/credit-insurance/index/index.spec.js b/client/client/src/credit-insurance/index/index.spec.js index 19128c821..7200ef493 100644 --- a/client/client/src/credit-insurance/index/index.spec.js +++ b/client/client/src/credit-insurance/index/index.spec.js @@ -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); + }); + }); }); }); diff --git a/services/order/common/methods/order/specs/itemFilter.spec.js b/services/order/common/methods/order/specs/itemFilter.spec.js new file mode 100644 index 000000000..fae219907 --- /dev/null +++ b/services/order/common/methods/order/specs/itemFilter.spec.js @@ -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); + }); +});