From 336472291deec38f6bf90935cb00080df9f71355 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 1 Apr 2021 18:38:40 +0200 Subject: [PATCH] test --- .../models/specs/supplier-account.spec.js | 66 +++++++++++++++++++ .../back/models/specs/supplier.spec.js | 2 +- .../back/models/supplier-account.json | 2 +- 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 modules/supplier/back/models/specs/supplier-account.spec.js diff --git a/modules/supplier/back/models/specs/supplier-account.spec.js b/modules/supplier/back/models/specs/supplier-account.spec.js new file mode 100644 index 000000000..438b87f8c --- /dev/null +++ b/modules/supplier/back/models/specs/supplier-account.spec.js @@ -0,0 +1,66 @@ +const app = require('vn-loopback/server/server'); +const LoopBackContext = require('loopback-context'); + +describe('loopback model Supplier-account', () => { + describe('create', () => { + const supplierId = 1; + const bankEntityId = 2100; + it('should throw an error when attempting to set an invalid iban account', async() => { + let error; + const expectedError = 'The IBAN does not have the correct format'; + const iban = 'incorrect format'; + // si falla el error es extraño preguntar a carlos + + await app.models.SupplierAccount.create( + { + supplierFk: supplierId, + bankEntityFk: bankEntityId, + iban: iban + } + ).catch(e => { + error = e; + + expect(error.message).toContain(expectedError); + }); + + expect(error).toBeDefined(); + }); + + it('should create a valid supplier account', async() => { + const tx = await app.models.Claim.beginTransaction({}); + try { + const options = {transaction: tx}; + const iban = 'ES91 2100 0418 4502 0005 1332'; + + const activeCtx = { + accessToken: {userId: 5}, + http: { + req: { + headers: {origin: 'http://localhost'} + } + } + }; + activeCtx.http.req.__ = value => { + return value; + }; + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + const createdSupplierAccount = await app.models.SupplierAccount.create( + { + supplierFk: supplierId, + bankEntityFk: bankEntityId, + iban: iban + } + , options); + + expect(createdSupplierAccount.iban).toBe(iban); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + }); +}); diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 1853b1c9a..f7dd15139 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -1,6 +1,6 @@ const app = require('vn-loopback/server/server'); -describe('loopback model address', () => { +describe('loopback model Supplier', () => { let supplierOne; let supplierTwo; diff --git a/modules/supplier/back/models/supplier-account.json b/modules/supplier/back/models/supplier-account.json index ffd2994ba..8e2838fe5 100644 --- a/modules/supplier/back/models/supplier-account.json +++ b/modules/supplier/back/models/supplier-account.json @@ -7,7 +7,7 @@ }, "options": { "mysql": { - "table": "supplierAccount" + "table": "supplierAccount" } }, "properties": {