issue it was us and not having comprehensive tests (process) ▪ const [rows, fields] = await connection.execute('SELECT * FROM `table`... I think we misread fields with rows (don’t clearly remember) ▪ What I remember though: ▫ 2 software engineers with relatively less experience with backend JS and JS concepts like promise ▫ Testing was in place but not enough to cover this service fee case ▫ Noone was fired, we fixed it and did a postmortem. 8
Goals: ▫ Use Mocha, Nock and Proxyquire to test an Express JS API (why not Jest, I am old school) ▫ The API will ▪ Have a DB with read/write operation ▪ Call an API for data ▫ Use Istanbul/nyc for code coverage 11
comes in node core itself ▪ Not using Sinon or any other library for mocking ▪ Stubbing responses per use case ▪ Rewire package might be used to test “private” methods (but do you want to do it?) ▪ For bigger projects it may not work (let’s talk “micro” services) 12
app a currency converter API ▪ It reads and write to a DB (MySQL) ▪ Call an external API for the currency rates ▪ Runs at: https://currency-api-nodejs.now.sh ▪ Code at: https://github.com/geshan/currency-api 13
coverage ▪ Always thoroughly test things that involve “Money” (don’t lose money due to one missing test :) simple) ▪ Use the tools of your choice, meet the goal. Tools are just one way to get to the goals. Wanna use Jest go for it. ▪ Write tests first (TDD) or tests last (test supported) but always write them ▪ Setup a continuous integration environment to get the feedback loop running, try out Werkcer CI (free) 15