From dcf5bf61dabae68a94d167bb95a25f768ae6ede1 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Mon, 19 Feb 2018 11:55:45 +0100 Subject: [PATCH] backend unit test for barcode duplicity plus e2e path completed --- client/item/src/barcode/item-barcode.html | 50 ++++++++--------- e2e/helpers/selectors.js | 10 +++- .../06_create_item_barcode.spec.js | 56 ++++++++++++++----- .../item/specs/crudItemBarcodes.spec.js | 21 +++++++ services/item/common/models/itemBarcode.json | 46 +++++++-------- 5 files changed, 121 insertions(+), 62 deletions(-) diff --git a/client/item/src/barcode/item-barcode.html b/client/item/src/barcode/item-barcode.html index 94b5e946a..985d3a02b 100644 --- a/client/item/src/barcode/item-barcode.html +++ b/client/item/src/barcode/item-barcode.html @@ -1,31 +1,31 @@
- - Item Barcodes - - - - - - - - - - + + Item Barcodes + + + + + + + + + + diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 38d312ffb..98035d8c2 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -145,8 +145,16 @@ export default { searchItemInput: `${components.vnTextfield}`, searchButton: `${components.vnSearchBar} > vn-icon-button > button` }, + itemBasicData: { + basicDataButton: `${components.vnMenuItem}[ui-sref="item.card.data"]` + }, itemBarcodes: { - barcodeButton: `${components.vnMenuItem}[ui-sref="item.card.itemBarcode"]` + barcodeButton: `${components.vnMenuItem}[ui-sref="item.card.itemBarcode"]`, + addBarcodeButton: `${components.vnIcon}[icon="add_circle"]`, + thirdCodeInput: `vn-horizontal:nth-child(5) > ${components.vnTextfield}`, + fourthCodeInput: `vn-horizontal:nth-child(6) > ${components.vnTextfield}`, + submitBarcodesButton: `${components.vnSubmit}`, + firstCodeRemoveButton: `vn-horizontal:nth-child(3) > vn-one > ${components.vnIcon}[icon="remove_circle_outline"]` } }; diff --git a/e2e/paths/item-module/06_create_item_barcode.spec.js b/e2e/paths/item-module/06_create_item_barcode.spec.js index af0a2bce2..9d4134672 100644 --- a/e2e/paths/item-module/06_create_item_barcode.spec.js +++ b/e2e/paths/item-module/06_create_item_barcode.spec.js @@ -55,17 +55,47 @@ describe('create item barcodes path', () => { .catch(catchErrors(done)); }); - // it(`should click on the search result to access to the item barcodes`, done => { - // nightmare - // .waitForTextInElement(selectors.itemsIndex.searchResult, 'Gem of Time') - // .waitToClick(selectors.itemsIndex.searchResult) - // .waitToClick(selectors.itemBarcodes.barcodeButton) - // .waitForURL('barcode') - // .url() - // .then(url => { - // expect(url).toContain('barcode'); - // done(); - // }) - // .catch(catchErrors(done)); - // }); + it(`should click on the search result to access to the item barcodes`, done => { + nightmare + .waitForTextInElement(selectors.itemsIndex.searchResult, 'Gem of Time') + .waitToClick(selectors.itemsIndex.searchResult) + .waitToClick(selectors.itemBarcodes.barcodeButton) + .waitForURL('barcode') + .url() + .then(url => { + expect(url).toContain('barcode'); + done(); + }) + .catch(catchErrors(done)); + }); + + it(`should click create a new code and delete a former one`, done => { + nightmare + .waitToClick(selectors.itemBarcodes.addBarcodeButton) + .type(selectors.itemBarcodes.fourthCodeInput, '5') + .click(selectors.itemBarcodes.firstCodeRemoveButton) + .click(selectors.itemBarcodes.submitBarcodesButton) + .wait(selectors.globalItems.snackbarIsActive) + .getInnerText(selectors.globalItems.snackbarIsActive) + .then(result => { + expect(result).toContain('Data saved!'); + done(); + }) + .catch(catchErrors(done)); + }); + + it(`should confirm the barcode 5 is created and it is now the third barcode as the first was deleted`, done => { + nightmare + .waitForSnackbarReset() + .click(selectors.itemBasicData.basicDataButton) + .wait(selectors.itemBasicData.nameInput) + .click(selectors.itemBarcodes.barcodeButton) + .wait(200) + .getInputValue(selectors.itemBarcodes.thirdCodeInput) + .then(result => { + expect(result).toEqual('5'); + done(); + }) + .catch(catchErrors(done)); + }); }); diff --git a/services/item/common/methods/item/specs/crudItemBarcodes.spec.js b/services/item/common/methods/item/specs/crudItemBarcodes.spec.js index 72365229a..d560677d9 100644 --- a/services/item/common/methods/item/specs/crudItemBarcodes.spec.js +++ b/services/item/common/methods/item/specs/crudItemBarcodes.spec.js @@ -1,7 +1,19 @@ const crudItemBarcodes = require('../crudItemBarcodes'); const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors; +let mysql = require('mysql2'); describe('Item crudItemBarcodes()', () => { + let connection; + beforeAll(() => { + connection = mysql.createConnection({ + multipleStatements: true, + host: 'localhost', + user: 'root', + password: '', + database: 'salix' + }); + }); + it('should call the destroyAll methodif there are ids in delete Array', done => { let self = jasmine.createSpyObj('self', ['remoteMethod', 'crudItemBarcodes', 'destroyAll', 'create', 'upsert']); @@ -48,4 +60,13 @@ describe('Item crudItemBarcodes()', () => { }) .catch(catchErrors(done)); }); + + it('should return an error when attempting to save a duplicated barcode', done => { + let callback = (err, res) => { + expect(err.toString()).toBe("Error: Duplicate entry '4' for key 'PRIMARY'"); + done(); + }; + + connection.query('INSERT INTO `vn`.`itemBarcode` VALUES (4, 2 ,4 );', callback); + }); }); diff --git a/services/item/common/models/itemBarcode.json b/services/item/common/models/itemBarcode.json index 9274cae98..8c089609f 100644 --- a/services/item/common/models/itemBarcode.json +++ b/services/item/common/models/itemBarcode.json @@ -1,28 +1,28 @@ { - "name": "ItemBarcode", - "base": "VnModel", - "options": { - "mysql": { - "table": "itemBarcode", - "database": "vn" - } - }, - "properties": { - "id": { - "type": "Number", - "id": true, - "description": "Identifier" - }, - "code": { - "type": "String", - "required": true + "name": "ItemBarcode", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemBarcode", + "database": "vn" } + }, + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "Identifier" }, - "relations": { - "item": { - "type": "belongsTo", - "model": "Item", - "foreignKey": "itemFk" - } + "code": { + "type": "String", + "required": true } + }, + "relations": { + "item": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "itemFk" + } } +}