diff --git a/.eslintrc.yml b/.eslintrc.yml index 101c70b1e..38ed89e45 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,5 +1,9 @@ -extends: [eslint:recommended, google] +extends: [eslint:recommended, google, plugin:jasmine/recommended] installedESLint: true +plugins: + - jasmine +env: + jasmine: true rules: indent: [error, 4] require-jsdoc: 0 diff --git a/client/client/src/address-create/address-create.spec.js b/client/client/src/address-create/address-create.spec.js index 24b54f9e2..9e1cd2e0d 100644 --- a/client/client/src/address-create/address-create.spec.js +++ b/client/client/src/address-create/address-create.spec.js @@ -17,6 +17,7 @@ describe('Client', () => { it('should define and set address property', () => { let controller = $componentController('vnAddressCreate', {$state: $state}); + expect(controller.address.clientFk).toBe(1234); expect(controller.address.enabled).toBe(true); }); diff --git a/client/client/src/address-edit/address-edit.spec.js b/client/client/src/address-edit/address-edit.spec.js index b2bbdc50d..4900a817e 100644 --- a/client/client/src/address-edit/address-edit.spec.js +++ b/client/client/src/address-edit/address-edit.spec.js @@ -17,6 +17,7 @@ describe('Client', () => { it('should define and set address property', () => { let controller = $componentController('vnAddressEdit', {$state: $state}); + expect(controller.address.id).toBe(1234); }); }); diff --git a/client/client/src/billing-data/billing-data.spec.js b/client/client/src/billing-data/billing-data.spec.js index c028bab67..b4fc84051 100644 --- a/client/client/src/billing-data/billing-data.spec.js +++ b/client/client/src/billing-data/billing-data.spec.js @@ -33,6 +33,7 @@ describe('Client', () => { }; controller.billData = {}; controller.copyData(controller.client); + expect(controller.billData).toEqual(controller.client); }); }); @@ -43,8 +44,8 @@ describe('Client', () => { spyOn(controller, 'checkPaymentChanges'); controller.submit() .then(() => { - expect(controller.$.watcher.submit).toHaveBeenCalled(); - expect(controller.checkPaymentChanges).toHaveBeenCalled(); + expect(controller.$.watcher.submit).toHaveBeenCalledWith(); + expect(controller.checkPaymentChanges).toHaveBeenCalledWith(); done(); }); }); @@ -56,6 +57,7 @@ describe('Client', () => { controller.billData = {marvelHero: 'Silver Surfer'}; controller.client = {marvelHero: 'Silver Surfer'}; controller.checkPaymentChanges(); + expect(controller.$.sendMail.show).not.toHaveBeenCalled(); }); @@ -64,7 +66,8 @@ describe('Client', () => { controller.billData = {marvelHero: 'Silver Surfer'}; controller.client = {marvelHero: 'Spider-Man'}; controller.checkPaymentChanges(); - expect(controller.$.sendMail.show).toHaveBeenCalled(); + + expect(controller.$.sendMail.show).toHaveBeenCalledWith(); }); }); diff --git a/client/client/src/card/card.spec.js b/client/client/src/card/card.spec.js index f63a3fc9a..a5c64bf7f 100644 --- a/client/client/src/card/card.spec.js +++ b/client/client/src/card/card.spec.js @@ -16,6 +16,7 @@ describe('Client', () => { it('should define and set client property to null in the module instance', () => { let controller = $componentController('vnClientCard', {$scope: $scope}); + expect(controller.client).toBeDefined(); expect(controller.client).toBe(null); }); diff --git a/client/client/src/create/create.spec.js b/client/client/src/create/create.spec.js index 881513b3b..609b5f013 100644 --- a/client/client/src/create/create.spec.js +++ b/client/client/src/create/create.spec.js @@ -27,6 +27,7 @@ describe('Client', () => { it('should define and set scope, state and client properties', () => { let controller = $componentController('vnClientCreate', {$scope: $scope}); + expect(controller.$).toBe($scope); expect(controller.$state).toBe($state); expect(controller.client.active).toBe(true); @@ -37,6 +38,7 @@ describe('Client', () => { let controller = $componentController('vnClientCreate', {$scope: $scope}); spyOn($state, 'go'); controller.onSubmit(); + expect(controller.$state.go).toHaveBeenCalledWith('clientCard.basicData', {id: '1234'}); }); }); diff --git a/client/client/src/descriptor/descriptor.spec.js b/client/client/src/descriptor/descriptor.spec.js index d5bfa119a..fd30d3889 100644 --- a/client/client/src/descriptor/descriptor.spec.js +++ b/client/client/src/descriptor/descriptor.spec.js @@ -18,10 +18,13 @@ describe('Client', () => { it('should check if active is defined and diferent from the new value', () => { let controller = $componentController('vnDescriptor', {$scope: $scope}); controller.client = {id: 1}; + expect(controller._active).toBe(undefined); controller.active = false; + expect(controller._active).toBe(false); controller.active = true; + expect(controller._active).toBe(true); }); }); diff --git a/client/client/src/index/index.spec.js b/client/client/src/index/index.spec.js index 48a34bf0a..9a4fe5e0f 100644 --- a/client/client/src/index/index.spec.js +++ b/client/client/src/index/index.spec.js @@ -14,6 +14,7 @@ describe('Client', () => { it('should define and set model property as an empty object', () => { let controller = $componentController('vnClientIndex'); + expect(controller.model).toEqual({}); }); @@ -28,6 +29,7 @@ describe('Client', () => { } }; controller.search(index); + expect(index.filter.search).toBe('batman'); }); }); diff --git a/client/client/src/note-create/note-create.spec.js b/client/client/src/note-create/note-create.spec.js index 444dc3ba3..52d2cfcb9 100644 --- a/client/client/src/note-create/note-create.spec.js +++ b/client/client/src/note-create/note-create.spec.js @@ -17,6 +17,7 @@ describe('Client', () => { it('should define clientFk using $state.params.id', () => { let controller = $componentController('vnNoteCreate', {$state: $state}); + expect(controller.note.clientFk).toBe(1234); expect(controller.note.client).toBe(undefined); }); diff --git a/client/client/src/notes/notes.spec.js b/client/client/src/notes/notes.spec.js index e5a771dc2..78d8092fc 100644 --- a/client/client/src/notes/notes.spec.js +++ b/client/client/src/notes/notes.spec.js @@ -24,6 +24,7 @@ describe('Client', () => { }; spyOn(controller, 'getObservation').and.returnValue(); controller.$onChanges(); + expect(controller.getObservation).toHaveBeenCalledWith(1234); }); }); @@ -46,6 +47,7 @@ describe('Client', () => { controller.client = {id: '1234'}; spyOn(controller.$state, 'go'); controller.newObservation(); + expect(controller.$state.go).toHaveBeenCalledWith('clientCard.notes.create', Object({id: '1234'})); }); }); diff --git a/client/client/src/search-panel/search-panel.spec.js b/client/client/src/search-panel/search-panel.spec.js index 514df7209..eacc74ac3 100644 --- a/client/client/src/search-panel/search-panel.spec.js +++ b/client/client/src/search-panel/search-panel.spec.js @@ -21,17 +21,20 @@ describe('Client', () => { spyOn(controller, 'onSubmit'); controller.setStorageValue(); controller.onSubmit(); - expect(controller.setStorageValue).toHaveBeenCalled(); - expect(controller.onSubmit).toHaveBeenCalled(); + + expect(controller.setStorageValue).toHaveBeenCalledWith(); + expect(controller.onSubmit).toHaveBeenCalledWith(); }); }); describe('$onChanges()', () => { it(`should set filter properties using the search values`, () => { let controller = $componentController('vnClientSearchPanel', {$window: $window}); + expect(controller.filter).not.toBeDefined(); spyOn(JSON, 'parse').and.returnValue({data: 'data'}); controller.$onChanges(); + expect(controller.filter).toBe(JSON.parse({data: 'data'})); }); }); diff --git a/client/client/src/web-access/web-access.spec.js b/client/client/src/web-access/web-access.spec.js index eb696ffa9..f19918425 100644 --- a/client/client/src/web-access/web-access.spec.js +++ b/client/client/src/web-access/web-access.spec.js @@ -24,6 +24,7 @@ describe('Component VnClientWebAccess', () => { controller.client = {client: 'Bruce Wayne', account: 'Wayne Industries'}; controller.account = {}; controller.$onChanges(); + expect(controller.account).toBe('Wayne Industries'); }); }); @@ -34,6 +35,7 @@ describe('Component VnClientWebAccess', () => { controller.newPassword = 'm24x8'; controller.repeatPassword = 'm24x8'; controller.onPassOpen(); + expect(controller.newPassword).toBe(''); expect(controller.repeatPassword).toBe(''); }); @@ -52,22 +54,24 @@ describe('Component VnClientWebAccess', () => { }); describe(`when password is empty`, () => { - it('should throw an error', () => { + it(`should throw Passwords can't be empty error`, () => { let controller = $componentController('vnClientWebAccess', {$scope: $scope}); controller.client = {id: '1234'}; controller.newPassword = ''; controller.onPassChange('ACCEPT'); + expect(vnApp.showError).toHaveBeenCalledWith(`Passwords can't be empty`); }); }); describe(`when passwords don't match`, () => { - it('should throw an error', () => { + it(`should throw Passwords don't match error`, () => { let controller = $componentController('vnClientWebAccess', {$scope: $scope}); controller.client = {id: '1234'}; controller.newPassword = 'm24x8'; controller.repeatPassword = 'notMatchingPassword'; controller.onPassChange('ACCEPT'); + expect(vnApp.showError).toHaveBeenCalledWith(`Passwords don't match`); }); }); diff --git a/client/core/src/autocomplete/autocomplete.spec.js b/client/core/src/autocomplete/autocomplete.spec.js index 67d88ef33..5d76a26d0 100644 --- a/client/core/src/autocomplete/autocomplete.spec.js +++ b/client/core/src/autocomplete/autocomplete.spec.js @@ -17,6 +17,7 @@ describe('Core', () => { it('should define and set address property', () => { let controller = $componentController('vnAddressCreate', {$state: $state}); + expect(controller.address.clientFk).toBe(1234); expect(controller.address.enabled).toBe(true); }); diff --git a/package.json b/package.json index c6bef2107..e3cfad2c2 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "eslint-config-loopback": "^4.0.0", "eslint-config-xo": "^0.17.0", "eslint-plugin-angular": "^1.4.1", + "eslint-plugin-jasmine": "^2.8.4", "file-loader": "^0.9.0", "gulp": "^3.9.1", "gulp-concat": "^2.6.0", diff --git a/services/client/common/methods/client/specs/create.spec.js b/services/client/common/methods/client/specs/create.spec.js index 760122e73..e168e6b33 100644 --- a/services/client/common/methods/client/specs/create.spec.js +++ b/services/client/common/methods/client/specs/create.spec.js @@ -1,32 +1,31 @@ -// import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; -// let app = require('../../../../server/server'); +import {catchErrors} from '../../../../../../services/utils/jasmineHelpers'; +let app = require('../../../../server/server'); -// describe('Client Create()', () => { +describe('Client Create()', () => { + let data = { + name: 'Max Eisenhardt', + userName: 'Magneto', + email: 'magneto@marvel.com', + fi: 'X-tax number', + socialName: 'The X-Men' + }; -// let data = { -// name: 'Max Eisenhardt', -// userName: 'Magneto', -// email: 'magneto@marvel.com', -// fi: 'X-tax number', -// socialName: 'The X-Men' -// } - -// it('should createa new account', (done) => { -// app.models.Client.createUserProfile(data, () => { -// app.models.Account.findOne({where: {name: data.userName}}) -// .then(account => { -// expect(account.name).toEqual(data.userName) -// app.models.Client.findOne({where: {name: data.name}}) -// .then(client => { -// expect(client.id).toEqual(account.id); -// expect(client.name).toEqual(data.name); -// expect(client.email).toEqual(data.email); -// expect(client.fi).toEqual(data.fi); -// expect(client.socialName).toEqual(data.socialName); -// done(); -// }); -// }) -// .catch(catchErrors(done)); -// }); -// }); -// }); \ No newline at end of file + it('should createa new account', done => { + app.models.Client.createUserProfile(data, () => { + app.models.Account.findOne({where: {name: data.userName}}) + .then(account => { + expect(account.name).toEqual(data.userName); + app.models.Client.findOne({where: {name: data.name}}) + .then(client => { + expect(client.id).toEqual(account.id); + expect(client.name).toEqual(data.name); + expect(client.email).toEqual(data.email); + expect(client.fi).toEqual(data.fi); + expect(client.socialName).toEqual(data.socialName); + done(); + }); + }) + .catch(catchErrors(done)); + }); + }); +}); diff --git a/services/production/common/methods/agency/list.js b/services/production/common/methods/agency/list.js index 5a5e067b8..41eca050c 100644 --- a/services/production/common/methods/agency/list.js +++ b/services/production/common/methods/agency/list.js @@ -1,7 +1,4 @@ -module.exports = function(Agency) { - - var serverFilter = {"where": {"isManaged": {"neq": 0}}}; - +module.exports = Agency => { + let serverFilter = {where: {isManaged: {neq: 0}}}; Agency.defineScope(serverFilter); - -} \ No newline at end of file +};