From a8b9e2c374c486ee2d07a424d6c31c82bddea1b0 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Tue, 11 Jun 2019 08:54:03 +0200 Subject: [PATCH] #1435 unitarios back hasActiveRecovery --- .../back/methods/recovery/hasActiveRecovery.js | 4 ++-- .../methods/recovery/hasActiveRecovery.spec.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 modules/client/back/methods/recovery/hasActiveRecovery.spec.js diff --git a/modules/client/back/methods/recovery/hasActiveRecovery.js b/modules/client/back/methods/recovery/hasActiveRecovery.js index 1fe1394d9..81a8a5f40 100644 --- a/modules/client/back/methods/recovery/hasActiveRecovery.js +++ b/modules/client/back/methods/recovery/hasActiveRecovery.js @@ -24,8 +24,8 @@ module.exports = Self => { Self.hasActiveRecovery = async id => { let result = await Self.rawSql( `SELECT count(*) AS hasActiveRecovery - FROM vn.recovery - WHERE clientFk = ? + FROM vn.recovery + WHERE clientFk = ? AND IFNULL(finished,CURDATE()) >= CURDATE();`, [id] ); diff --git a/modules/client/back/methods/recovery/hasActiveRecovery.spec.js b/modules/client/back/methods/recovery/hasActiveRecovery.spec.js new file mode 100644 index 000000000..218d10df5 --- /dev/null +++ b/modules/client/back/methods/recovery/hasActiveRecovery.spec.js @@ -0,0 +1,15 @@ +const app = require('vn-loopback/server/server'); + +describe('client hasActiveRecovery', () => { + it(`should return false if the client doesn't owes`, async() => { + let hasActiveRecovery = await app.models.Recovery.hasActiveRecovery(101); + + expect(hasActiveRecovery).toBeFalsy(); + }); + + it('should return true if the client owes', async() => { + let hasActiveRecovery = await app.models.Recovery.hasActiveRecovery(102); + + expect(hasActiveRecovery).toBeTruthy(); + }); +});