diff --git a/modules/client/back/methods/client/specs/sendSms.spec.js b/modules/client/back/methods/client/specs/sendSms.spec.js new file mode 100644 index 000000000..b299ac3c1 --- /dev/null +++ b/modules/client/back/methods/client/specs/sendSms.spec.js @@ -0,0 +1,27 @@ +const app = require('vn-loopback/server/server'); + +describe('client sendSms()', () => { + let createdLog; + + afterAll(async done => { + await app.models.ClientLog.destroyById(createdLog.id); + + done(); + }); + + it('should send a message and log it', async() => { + let ctx = {req: {accessToken: {userId: 9}}}; + let id = 101; + let destination = 222222222; + let message = 'this is the message created in a test'; + + let sms = await app.models.Client.sendSms(ctx, id, destination, message); + + logId = sms.logId; + + createdLog = await app.models.ClientLog.findById(logId); + let json = JSON.parse(JSON.stringify(createdLog.newInstance)); + + expect(json.message).toEqual(message); + }); +}); diff --git a/modules/client/back/methods/sms/send.spec.js b/modules/client/back/methods/sms/send.spec.js new file mode 100644 index 000000000..612a16cf1 --- /dev/null +++ b/modules/client/back/methods/sms/send.spec.js @@ -0,0 +1,37 @@ +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; + const smsConfig = await app.models.SmsConfig.findOne(); + const soapClient = await soap.createClientAsync(smsConfig.uri); + spyOn(soap, 'createClientAsync').and.returnValue(soapClient); + spyOn(soapClient, 'sendSMSAsync').and.returnValue([{ + result: { + $value: + ` + + + ${code} + + + Envio en procesamiento + + + 1 + + + + 444328681 + + ` + } + }]); + let ctx = {req: {accessToken: {userId: 1}}}; + let result = await app.models.Sms.send(ctx, 105, 'destination', 'My SMS Body'); + + expect(result.statusCode).toEqual(200); + expect(result.status).toContain('Fake response'); + }); +}); diff --git a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js new file mode 100644 index 000000000..20066a5ba --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js @@ -0,0 +1,27 @@ +const app = require('vn-loopback/server/server'); + +describe('ticket sendSms()', () => { + let logId; + + afterAll(async done => { + await app.models.TicketLog.destroyById(logId); + + done(); + }); + + it('should send a message and log it', async() => { + let ctx = {req: {accessToken: {userId: 9}}}; + let id = 11; + let destination = 222222222; + let message = 'this is the message created in a test'; + + let sms = await app.models.Ticket.sendSms(ctx, id, destination, message); + + logId = sms.logId; + + let createdLog = await app.models.TicketLog.findById(logId); + let json = JSON.parse(JSON.stringify(createdLog.newInstance)); + + expect(json.message).toEqual(message); + }); +});