import { QBOClient } from '../src/client'; import { QBOService, QBOCustomer, QBOInvoice } from '../src/models'; import nock = require('nock'); import { expect } from 'chai'; import 'mocha'; describe('QBOClient', () => { const client: QBOClient = new QBOClient("client_id", "client_secret", "20000", true); describe('Customers', () => { it('should retrieve a list of customers', () => { const json: any = require('./fixtures/customers.json'); nock('https://sandbox-quickbooks.api.intuit.com') .get('/v3/company/20000/query') .query(true) .reply(200, json); return client.getAllCustomers() .then((customers: QBOCustomer[]) => { expect(customers.length).to.equal(2); expect(customers[0].id).to.equal(58); expect(customers[0].displayName).to.equal("Customer I"); expect(customers[0].companyName).to.equal("Customer I"); expect(customers[0].fullyQualifiedName).to.equal("QBO:Customer I"); expect(customers[1].id).to.equal(66); expect(customers[1].displayName).to.equal("Customer II"); expect(customers[1].companyName).to.equal("Customer II"); expect(customers[1].fullyQualifiedName).to.equal("QBO:Customer II"); }) .catch((error: Error) => { expect.fail(0, 1, "Should not throw an exception: " + error.message); }); }); }); }); describe('QBOClient', () => { const client: QBOClient = new QBOClient("client_id", "client_secret", "20000", true); describe('Items', () => { it('should query items by category', () => { const json: any = require('./fixtures/services.json'); nock('https://sandbox-quickbooks.api.intuit.com') .get('/v3/company/20000/query') .query(true) .reply(200, json); return client.getServicesByCategory(21) .then((response: QBOService[]) => { expect(response.length).to.equal(4); }) .catch((error: Error) => { expect.fail(0, 1, "Should not throw an exception"); }); }); }); }); describe('QBOClient :: Invoices', () => { const client: QBOClient = new QBOClient("client_id", "client_secret", "20000", true); describe('Invoices', () => { it('should fetch last invoice', () => { const json: any = require('./fixtures/invoices.json'); nock('https://sandbox-quickbooks.api.intuit.com') .get('/v3/company/20000/query') .query(true) .reply(200, json); return client.getLastClientInvoice(58) .then((invoice: QBOInvoice | null) => { expect(invoice).to.not.be.null; if( invoice != null ) { expect(invoice.id).to.equal(158); } }) .catch((error: Error) => { expect.fail(0, 1, "Should not throw an exception"); }) }); }); });