How can I mock this 'getQbo' function ?
Have this library
// quickbooks module.ts
var QuickBooks = require('node-quickbooks');
export function getQbo (token, companyId, refresh) {
return new QuickBooks(process.env.QB_CLIENT_ID,
process.env.QB_CLIENT_SECRET,
token, /* oAuth access token */
false, /* no token secret for oAuth 2.0 */
companyId,
true, /* use a sandbox account */
true, /* turn debugging on */
4, /* minor version */
'2.0', /* oauth version */
refresh /* refresh token */);
}
Imported like this
// paymetn.module.ts
import {getQbo} from "./../../../utils/quickBooks/qbo.module";
var mock = sinon.mock(QuickBooks);
var stub = sinon.stub(QuickBooks, “getQbo”);
var mock = sinon.mock(getQbo);
var stub = sinon.stub(getQbo, “getQbo”);
response
calls, I've tried to call it with .call
and .apply
to set what this
should be, and a number of other things, but this
is always {}
inside the intent object
this
inside that object so I can test if they're called?
const handlers = {
'HelloWorldIntent' : function() {
//emit response directly
this.emit(':tell', 'Hello World!');
}
};
this
as planned - gotta do some reading as to why the arrows weren't working
// Import qbs
import {getQbo} from "./../../utils/quickBooks/qbo.module";
// My new instance
const invoiceModule: InvoiceModule = new InvoiceModule(getQbo);
// My class
export class InvoiceModule {
qbo: any;
addressModule: AddressModule = new AddressModule();
customerModule: CustomerModule = new CustomerModule();
emailModule: EmailModule = new EmailModule();
constructor(getQbo) {
const token = process.env.QB_APP_TOKEN;
const companyId = process.env.QB_COMPANY_ID;
const refresh = process.env.QB_APP_TOKEN_REFRESH;
this.qbo = getQbo(token, companyId, refresh);
}
}
@jeffhall-wk sorry for the wait. Hope it helps
before(marbles(function(m) {
composeInvoiceEmailHtmlMock = sinon.stub(InvoiceModule.prototype,'composeInvoiceEmailHtml')
.returns('<p>It was mocked</p>');*/
composeCustomerMock$ = sinon.stub(InvoiceModule.prototype, 'composeCustomerAndCreateCustomerInQBO')
.returns(m.cold('--a|', {a: customerMock}));
composeInvoiceMock$ = sinon.stub(InvoiceModule.prototype, 'composeInvoiceAndCreateInvoiceInQBO')
.returns(m.cold('--a|', {a: invoiceMock}));
sendEmailMock$ = sinon.stub(InvoiceModule.prototype, 'sendEmail$')
.returns(m.cold('--a|', {a: 'SENT_EMAIL'}));
}));
after(function () {
composeCustomerMock$.restore();
composeInvoiceMock$.restore();
sendEmailMock$.restore();
})
it('should create an invoice in QBO', marbles(function(m) {
const b = m.cold('------b', {b: 'SENT_EMAIL'});
m.expect(invoiceModule.createCustomerAndInvoiceInQBO$(rawDocument)).toBeObservable(b);
}));
it('should do something with stubs', sinon.test(function() {
var stub = this.stub($, 'post');
doSomething();
sinon.assert.calledOnce(stub);
});
var sinon = require('sinon');
let sinonTestFactory = require("sinon-test");
let sinonTest = sinonTestFactory(sinon);
it('should test the createECHeckCharge function', sinonTest(function() {
const that = this;
marbles(m => {
that.stub(request, 'post').yields(null, {OK: true}, {status: 'CAPTURED'});
m.expect(paymentModule.createCharge({})).toBeObservable(m.cold('a', {a: {status: 'CAPTURED'}}))
})()
}));
const callback = spy.stub(exampleFn())
, then does that mean the callback
will be able to do the job of my exampleFn
?