diff --git a/modules/client/back/methods/client/sendSms.js b/modules/client/back/methods/client/sendSms.js index 18651c65c..a39d4c75a 100644 --- a/modules/client/back/methods/client/sendSms.js +++ b/modules/client/back/methods/client/sendSms.js @@ -48,7 +48,9 @@ module.exports = Self => { } }; - await Self.app.models.ClientLog.create(logRecord); + const clientLog = await Self.app.models.ClientLog.create(logRecord); + + sms.logId = clientLog.id; return sms; }; 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..06435fdbd --- /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 clientLog; + + afterAll(async done => { + await app.models.ClientLog.destroyById(clientLog.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; + + let 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/front/sms/index.spec.js b/modules/client/front/sms/index.spec.js index 6018825e9..c2a7eb935 100644 --- a/modules/client/front/sms/index.spec.js +++ b/modules/client/front/sms/index.spec.js @@ -14,6 +14,7 @@ describe('Client', () => { $element = angular.element(''); controller = $componentController('vnClientSms', {$element, $scope}); controller.client = {id: 101}; + controller.$params = {id: 101}; })); describe('onResponse()', () => { @@ -22,8 +23,7 @@ describe('Client', () => { controller.sms = {destinationFk: 101, destination: 111111111, message: 'My SMS'}; spyOn(controller.vnApp, 'showMessage'); - $httpBackend.when('POST', `Sms/send`, params).respond(200, params); - $httpBackend.expect('POST', `Sms/send`, params).respond(params); + $httpBackend.expect('POST', `Clients/101/sendSms`, params).respond(200, params); controller.onResponse('accept'); $httpBackend.flush(); diff --git a/modules/ticket/back/methods/ticket/sendSms.js b/modules/ticket/back/methods/ticket/sendSms.js index f4fe82315..efcaf4eda 100644 --- a/modules/ticket/back/methods/ticket/sendSms.js +++ b/modules/ticket/back/methods/ticket/sendSms.js @@ -48,7 +48,9 @@ module.exports = Self => { } }; - await Self.app.models.TicketLog.create(logRecord); + const ticketLog = await Self.app.models.TicketLog.create(logRecord); + + sms.logId = ticketLog.id; return sms; }; 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); + }); +}); diff --git a/modules/ticket/front/sms/index.spec.js b/modules/ticket/front/sms/index.spec.js index cc76d4ce1..5565c3623 100644 --- a/modules/ticket/front/sms/index.spec.js +++ b/modules/ticket/front/sms/index.spec.js @@ -1,30 +1,28 @@ import './index'; -describe('Client', () => { - describe('Component vnClientSms', () => { +describe('Ticket', () => { + describe('Component vnTicketSms', () => { let controller; let $httpBackend; let $element; - beforeEach(ngModule('client')); + beforeEach(ngModule('ticket')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; let $scope = $rootScope.$new(); $element = angular.element(''); - controller = $componentController('vnClientSms', {$element, $scope}); - controller.client = {id: 101}; + controller = $componentController('vnTicketSms', {$element, $scope}); + controller.$params = {id: 11}; })); describe('onResponse()', () => { it('should perform a POST query and show a success snackbar', () => { - const ticketId = 11; let params = {destinationFk: 101, destination: 111111111, message: 'My SMS'}; controller.sms = {destinationFk: 101, destination: 111111111, message: 'My SMS'}; spyOn(controller.vnApp, 'showMessage'); - $httpBackend.when('POST', `Ticket/${ticketId}/sendSms`, params).respond(200, params); - $httpBackend.expect('POST', `Sms/send`, params).respond(params); + $httpBackend.expect('POST', `Tickets/11/sendSms`, params).respond(200, params); controller.onResponse('accept'); $httpBackend.flush();