test(send): backTest and fixtures
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-01-11 08:39:06 +01:00
parent ebac06e4fc
commit 9e491082e7
5 changed files with 20 additions and 22 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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();
});
});