import { Request, Response } from 'express';
import MessageSender form '../Services/MessageSender';
/**
* Example controller that provides a healthcheck endpoint
*/
module Example {
'use strict';
/*
* Return an empty 200 response
*/
export function someMethod (req: Request, res: Response) {
// this is where you can inject your mock
const messageSender = this._messageSender || new MessageSender();
messageSender.SendMessage("hello world!")
.then(() => res.end);
}
}
export = Example;
import sinon from 'sinon';
import sinonStubPromise from 'sinon-stub-promise';
import { someMethod } from './Example';
sinonStubPromise(sinon);
describe('Example Controller', () => {
describe('someMethod', () => {
it('should send a message', () => {
const sendMessagePromise = sinon.stub().returnsPromise();
const messageSenderMock = {
sendMessage: (message) => {
sendMessagePromise.resolves({sid: 'MSXXXXXXXXXXXXXXXXXXXXXXXXX', body: message});
}
};
someMethod._messageSender = messageSenderMock;
someMethod({}, {});
expect(sendMessagePromise.resolved).to.eql({sid: 'MSXXXXXXXXXXXXXXXXXXXXXXXXX', body: 'hello world!'});
});
})
});