sendSms test
gitea/salix/1998-client_sms This commit looks good
Details
gitea/salix/1998-client_sms This commit looks good
Details
This commit is contained in:
parent
b42b2ec8c3
commit
ba2300288f
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -14,6 +14,7 @@ describe('Client', () => {
|
|||
$element = angular.element('<vn-dialog></vn-dialog>');
|
||||
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();
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -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('<vn-dialog></vn-dialog>');
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue