From 9e491082e74a5f13595dfc5fe7fae375747d0ca1 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 11 Jan 2022 08:39:06 +0100 Subject: [PATCH] test(send): backTest and fixtures --- db/changes/10410-noname/00-smsConfig.sql | 10 +--------- db/changes/10410-noname/01-smsConfig_update.sql | 7 +++++++ db/dump/fixtures.sql | 4 ++-- modules/client/back/methods/sms/send.js | 9 ++++++--- modules/client/back/methods/sms/send.spec.js | 12 ++++-------- 5 files changed, 20 insertions(+), 22 deletions(-) create mode 100644 db/changes/10410-noname/01-smsConfig_update.sql diff --git a/db/changes/10410-noname/00-smsConfig.sql b/db/changes/10410-noname/00-smsConfig.sql index 64e6450d5..b3f1610d4 100644 --- a/db/changes/10410-noname/00-smsConfig.sql +++ b/db/changes/10410-noname/00-smsConfig.sql @@ -1,13 +1,5 @@ ALTER TABLE `vn`.`smsConfig` ADD apiKey varchar(50) NULL; - -UPDATE `vn`.`smsConfig` - SET `uri` = 'https://api.gateway360.com/api/3.0/sms/send' - WHERE `id` = 1; - -UPDATE `vn`.`smsConfig` - SET `apiKey`='5715476da95b46d686a5a255e6459523' - WHERE `id` = 1; - ALTER TABLE `vn`.`smsConfig` CHANGE `user` user__ varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL; ALTER TABLE `vn`.`smsConfig` CHANGE password password__ varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL; ALTER TABLE `vn`.`sms` MODIFY COLUMN statusCode smallint(9) DEFAULT 0 NULL; +ALTER TABLE `vn`.`sms` MODIFY COLUMN status varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT 'OK' NULL; diff --git a/db/changes/10410-noname/01-smsConfig_update.sql b/db/changes/10410-noname/01-smsConfig_update.sql new file mode 100644 index 000000000..c4b4c895e --- /dev/null +++ b/db/changes/10410-noname/01-smsConfig_update.sql @@ -0,0 +1,7 @@ +UPDATE `vn`.`smsConfig` + SET `uri` = 'https://api.gateway360.com/api/3.0/sms/send' + WHERE `id` = 1; + +UPDATE `vn`.`smsConfig` + SET `apiKey` = '5715476da95b46d686a5a255e6459523' + WHERE `id` = 1; \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 6ba9c00e8..8274da0e1 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1906,9 +1906,9 @@ INSERT INTO `postgresql`.`calendar_employee` (`business_id`, `calendar_state_id` (1107, 1, IF(MONTH(CURDATE()) >= 1 AND DAY(CURDATE()) > 20, DATE_ADD(CURDATE(), INTERVAL -14 DAY), DATE_ADD(CURDATE(), INTERVAL 9 DAY))), (1107, 2, IF(MONTH(CURDATE()) >= 1 AND DAY(CURDATE()) > 20, DATE_ADD(CURDATE(), INTERVAL -15 DAY), DATE_ADD(CURDATE(), INTERVAL 7 DAY))); -INSERT INTO `vn`.`smsConfig` (`id`, `uri`, `title`) +INSERT INTO `vn`.`smsConfig` (`id`, `uri`, `title`, `apiKey`) VALUES - ('1', 'https://websms.xtratelecom.es/api_php/server.wsdl', 'Verdnatura'); + ('1', 'https://api.gateway360.com/api/3.0/sms/send', 'Verdnatura', '5715476da95b46d686a5a255e6459523'); INSERT INTO `vn`.`sharingClient`(`id`, `workerFk`, `started`, `ended`, `clientFk`) VALUES diff --git a/modules/client/back/methods/sms/send.js b/modules/client/back/methods/sms/send.js index 270b622c2..325e2e60d 100644 --- a/modules/client/back/methods/sms/send.js +++ b/modules/client/back/methods/sms/send.js @@ -34,6 +34,8 @@ module.exports = Self => { Self.send = async(ctx, destinationFk, destination, message) => { const userId = ctx.req.accessToken.userId; const smsConfig = await Self.app.models.SmsConfig.findOne(); + /* if (destination.length <= 9) + destination = '34' + destination;*/ const params = { api_key: smsConfig.apiKey, messages: [{ @@ -47,6 +49,7 @@ module.exports = Self => { try { if (process.env.NODE_ENV !== 'production') params.fake = 1; + const jsonTest = { json: params }; @@ -56,19 +59,19 @@ module.exports = Self => { } const [result] = response.result; - const status = result.error_id; + const error = result.error_id; const newSms = { senderFk: userId, destinationFk: destinationFk || null, destination: destination, message: message, - status: status + status: error }; const sms = await Self.create(newSms); - if (status) + if (error) throw new UserError(`We weren't able to send this SMS`); return sms; diff --git a/modules/client/back/methods/sms/send.spec.js b/modules/client/back/methods/sms/send.spec.js index c39e2ad6e..910b7d7b2 100644 --- a/modules/client/back/methods/sms/send.spec.js +++ b/modules/client/back/methods/sms/send.spec.js @@ -1,14 +1,10 @@ const app = require('vn-loopback/server/server'); -const soap = require('soap'); describe('sms send()', () => { - it('should return the expected message and status code', async() => { - const code = 200; - spyOn(soap, 'createClientAsync').and.returnValue('a so fake client'); - let ctx = {req: {accessToken: {userId: 1}}}; - let result = await app.models.Sms.send(ctx, 1105, 'destination', 'My SMS Body'); + it('should not return status error', async() => { + const ctx = {req: {accessToken: {userId: 1}}}; + const result = await app.models.Sms.send(ctx, 1105, '123123123', 'My SMS Body'); - expect(result.statusCode).toEqual(code); - expect(result.status).toContain('Fake response'); + expect(result.status).toBeUndefined(); }); });