Getting started with Nodejs and QuickBooks Online Part 3
Let's get npm test working
In part 1 and part 2 we just got our feet wet. An important part of digging deeper is to check out the tests, which display more complex transactions. Now, in part 3 we will get npm test working being it is not as simple as you might think.
- Grab the latest from
node-quickbooksor your fork of it. - I noticed some changes in for
example/package.jsonafter the upstream pull so: - Edit
example/app.jsand make the following mods: - Still in the
exampledir do anodemon app.js - Go to the browser
http://localhost:3000/. - Click the "Connect to QuickBooks" button and authenticate with your sandbox.
- Go back to your console running
nodemon app.jsand you should see the information we need for theconfig.js - You can shutdown the
exampleapp now. - Create a
.envfile (don't commit to source control) in the project root directory looking like this: - Make sure to "source" this file in all of your console windows:
source .env - Edit
config.jsto look like this: - Now you are ready to run the tests, so again in the console that you ran
source .envrunnpm test
git checkout pull upstream master
I am back to using the node-quickbooks master so in that regard I am not picking up directly from part 2.
We need to spin up the example app again to get the access tokens and realm id so we can record them into config.js, which is used by npm test to properly talk to your sandbox.
$ cd example $ npm install
-var consumerKey = '', - consumerSecret = '' +var consumerKey = process.env.MINIMULCASTS_CONSUMER_KEY, // substitute your env variable here + consumerSecret = process.env.MINIMULCASTS_CONSUMER_SECRET // ... - true); // turn debugging on + false); // turn debugging off // ... accounts.QueryResponse.Account.forEach(function(account) { - console.log(account.Name) + //console.log(account.Name) })
Make sure your Intuit app is enabled both for "QuickBooks" & "Payments" or you will get an error when connecting.
export OAUTH_TOKEN_SECRET=[ paste secret here (from step 7) ] export OAUTH_TOKEN=[ paste token here ] export REALM_ID=[ paste realm id here ]
module.exports = {
consumerKey: process.env.MINIMULCASTS_CONSUMER_KEY, // change for your app's consumer key
consumerSecret: process.env.MINIMULCASTS_CONSUMER_SECRET, // change for your app's consumer secret
token: process.env.OAUTH_TOKEN,
tokenSecret: process.env.OAUTH_TOKEN_SECRET,
realmId: process.env.REALM_ID,
useSandbox: true,
debug: false,
//
// Set useSandbox to false when moving to production. For info, see the following url:
// https://developer.intuit.com/v2/blog/2014/10/24/intuit-developer-now-offers-quickbooks-sandboxes
testEmail: '' // Use this email address for testing send*Pdf functions
}
$ source .env $ npm test
Conclusion
That's a wrap for part 3, in which we "simply" got the tests running. In part 4 I am going to be leveraging this test setup to answer a question on the Intuit developer forums that will show how you can leverage the tests to getting going on more complex transactions. Also, reference the code for this and part 4 of the tutorial.
- Pushed on 09/15/2015 by Christian
- QuickBooks Integration Consulting
