75 lines
2.9 KiB
JavaScript
75 lines
2.9 KiB
JavaScript
|
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:
|
||
|
`<xtratelecom-sms-response>
|
||
|
<sms>
|
||
|
<codigo>
|
||
|
${code}
|
||
|
</codigo>
|
||
|
<descripcion>
|
||
|
Envio en procesamiento
|
||
|
</descripcion>
|
||
|
<messageId>
|
||
|
1
|
||
|
</messageId>
|
||
|
</sms>
|
||
|
<procesoId>
|
||
|
444328681
|
||
|
</procesoId>
|
||
|
</xtratelecom-sms-response>`
|
||
|
}
|
||
|
}]);
|
||
|
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('Envio en procesamiento');
|
||
|
});
|
||
|
|
||
|
it(`should throw if the response code isn't 200`, async() => {
|
||
|
let error;
|
||
|
const code = 400;
|
||
|
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:
|
||
|
`<xtratelecom-sms-response>
|
||
|
<sms>
|
||
|
<codigo>
|
||
|
${code}
|
||
|
</codigo>
|
||
|
<descripcion>
|
||
|
Envio en procesamiento
|
||
|
</descripcion>
|
||
|
<messageId>
|
||
|
1
|
||
|
</messageId>
|
||
|
</sms>
|
||
|
<procesoId>
|
||
|
444328681
|
||
|
</procesoId>
|
||
|
</xtratelecom-sms-response>`
|
||
|
}
|
||
|
}]);
|
||
|
let ctx = {req: {accessToken: {userId: 1}}};
|
||
|
try {
|
||
|
await app.models.Sms.send(ctx, 105, 'destination', 'My SMS Body');
|
||
|
} catch (err) {
|
||
|
error = err;
|
||
|
}
|
||
|
|
||
|
expect(error.message).toEqual(`We weren't able to send this SMS`);
|
||
|
});
|
||
|
});
|