test(send): backTest and fixtures
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
ebac06e4fc
commit
9e491082e7
|
@ -1,13 +1,5 @@
|
||||||
ALTER TABLE `vn`.`smsConfig` ADD apiKey varchar(50) NULL;
|
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 `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`.`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 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;
|
||||||
|
|
|
@ -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;
|
|
@ -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, 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)));
|
(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
|
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`)
|
INSERT INTO `vn`.`sharingClient`(`id`, `workerFk`, `started`, `ended`, `clientFk`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -34,6 +34,8 @@ module.exports = Self => {
|
||||||
Self.send = async(ctx, destinationFk, destination, message) => {
|
Self.send = async(ctx, destinationFk, destination, message) => {
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
const smsConfig = await Self.app.models.SmsConfig.findOne();
|
const smsConfig = await Self.app.models.SmsConfig.findOne();
|
||||||
|
/* if (destination.length <= 9)
|
||||||
|
destination = '34' + destination;*/
|
||||||
const params = {
|
const params = {
|
||||||
api_key: smsConfig.apiKey,
|
api_key: smsConfig.apiKey,
|
||||||
messages: [{
|
messages: [{
|
||||||
|
@ -47,6 +49,7 @@ module.exports = Self => {
|
||||||
try {
|
try {
|
||||||
if (process.env.NODE_ENV !== 'production')
|
if (process.env.NODE_ENV !== 'production')
|
||||||
params.fake = 1;
|
params.fake = 1;
|
||||||
|
|
||||||
const jsonTest = {
|
const jsonTest = {
|
||||||
json: params
|
json: params
|
||||||
};
|
};
|
||||||
|
@ -56,19 +59,19 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const [result] = response.result;
|
const [result] = response.result;
|
||||||
const status = result.error_id;
|
const error = result.error_id;
|
||||||
|
|
||||||
const newSms = {
|
const newSms = {
|
||||||
senderFk: userId,
|
senderFk: userId,
|
||||||
destinationFk: destinationFk || null,
|
destinationFk: destinationFk || null,
|
||||||
destination: destination,
|
destination: destination,
|
||||||
message: message,
|
message: message,
|
||||||
status: status
|
status: error
|
||||||
};
|
};
|
||||||
|
|
||||||
const sms = await Self.create(newSms);
|
const sms = await Self.create(newSms);
|
||||||
|
|
||||||
if (status)
|
if (error)
|
||||||
throw new UserError(`We weren't able to send this SMS`);
|
throw new UserError(`We weren't able to send this SMS`);
|
||||||
|
|
||||||
return sms;
|
return sms;
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
const soap = require('soap');
|
|
||||||
|
|
||||||
describe('sms send()', () => {
|
describe('sms send()', () => {
|
||||||
it('should return the expected message and status code', async() => {
|
it('should not return status error', async() => {
|
||||||
const code = 200;
|
const ctx = {req: {accessToken: {userId: 1}}};
|
||||||
spyOn(soap, 'createClientAsync').and.returnValue('a so fake client');
|
const result = await app.models.Sms.send(ctx, 1105, '123123123', 'My SMS Body');
|
||||||
let ctx = {req: {accessToken: {userId: 1}}};
|
|
||||||
let result = await app.models.Sms.send(ctx, 1105, 'destination', 'My SMS Body');
|
|
||||||
|
|
||||||
expect(result.statusCode).toEqual(code);
|
expect(result.status).toBeUndefined();
|
||||||
expect(result.status).toContain('Fake response');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue