SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
@geshan
We lost $ 20.5K in one day and
how we could have saved it…
hint: better automated testing
Geshan Manandhar
Senior Software Engineer (THE ICONIC)
@geshan
whoami
▪ Senior Software Engineer
▫ Tech Solution provider
▪ Agile follower
▪ Conditional microservices believer
2
I am from Kathmandu, Nepal
I was working for a GFG venture in Middle East
Now I work at THE ICONIC
@geshan
One day early 2017 we deployed a new app
rewrite and lost 20.5 K USD in ~24 hours? How?
With 5 or less lines of code
6
@geshan
These 5 lines of code
return isFirstShipmentofOrder(connection,
orderData.fk_sales_order).then(isFirstShipment => {
isFirstShipment = isFirstShipment[0]; //this was always false
let serviceFee = isFirstShipment ?
parseFloat(orderData.shipping_amount) +
parseFloat(orderData.payment_fees) : 0; //so this was always 0
…
}7
@geshan
Not blaming anyone
▪ Mysql2 library was not the 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
@geshan9
End of Story => Start of the tutorial
@geshan10
Most tech tutorials
be like (probably not
this one, not sure)
@geshan
This talk is about
testing not the story
▪ 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
@geshan
Minimalist approach
(opinionated)
▪ Using assert (not chai) - 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
@geshan
Currency Converter
API
▪ Let's start with a simple 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
@geshan14
Demo Time
@geshan
Conclusion
▪ Write tests for confidence not 100% code 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
@geshan16
http://bit.ly/au-work-visa
@geshan
THANKS!
Any questions?
You can find me at @geshan and Geshan.com.np
Slides at: http://bit.ly/testing-nodejs
17

Más contenido relacionado

La actualidad más candente

Being a pimp without silverlight
Being a pimp without silverlightBeing a pimp without silverlight
Being a pimp without silverlight
Maarten Balliauw
 

La actualidad más candente (7)

Getting deep into Laravel mailables
Getting deep into Laravel mailablesGetting deep into Laravel mailables
Getting deep into Laravel mailables
 
Event streams all the way down
Event streams all the way downEvent streams all the way down
Event streams all the way down
 
Surviving with thin controllers and models
Surviving with thin controllers and modelsSurviving with thin controllers and models
Surviving with thin controllers and models
 
Being a pimp without silverlight
Being a pimp without silverlightBeing a pimp without silverlight
Being a pimp without silverlight
 
Ajax Technology
Ajax TechnologyAjax Technology
Ajax Technology
 
Vector artwork services
Vector artwork servicesVector artwork services
Vector artwork services
 
ReactJS - Re-rendering pages in the age of the mutable DOM
ReactJS - Re-rendering pages in the age of the mutable DOMReactJS - Re-rendering pages in the age of the mutable DOM
ReactJS - Re-rendering pages in the age of the mutable DOM
 

Similar a We lost $ 20.5K in one day and how we could have saved it… hint: better automated testing

BDD for RIAs with JavaScript - Skills Matter
BDD for RIAs with JavaScript - Skills MatterBDD for RIAs with JavaScript - Skills Matter
BDD for RIAs with JavaScript - Skills Matter
Carlos Ble
 
Responsive, adaptive and responsible - keynote at NebraskaJS
Responsive, adaptive and responsible - keynote at NebraskaJSResponsive, adaptive and responsible - keynote at NebraskaJS
Responsive, adaptive and responsible - keynote at NebraskaJS
Christian Heilmann
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
singingfish
 

Similar a We lost $ 20.5K in one day and how we could have saved it… hint: better automated testing (20)

Js basics
Js basicsJs basics
Js basics
 
Data weave 2.0 language fundamentals
Data weave 2.0 language fundamentalsData weave 2.0 language fundamentals
Data weave 2.0 language fundamentals
 
Choosing the Right Database - Facebook DevC Malang Hackdays 2017
Choosing the Right Database - Facebook DevC Malang Hackdays 2017Choosing the Right Database - Facebook DevC Malang Hackdays 2017
Choosing the Right Database - Facebook DevC Malang Hackdays 2017
 
AppDynamics User Group
AppDynamics User GroupAppDynamics User Group
AppDynamics User Group
 
BDD for RIAs with JavaScript - Skills Matter
BDD for RIAs with JavaScript - Skills MatterBDD for RIAs with JavaScript - Skills Matter
BDD for RIAs with JavaScript - Skills Matter
 
Java 8 - Gateway Drug or End of Line?
Java 8 - Gateway Drug or End of Line?Java 8 - Gateway Drug or End of Line?
Java 8 - Gateway Drug or End of Line?
 
DataWeave 2.0 Language Fundamentals
DataWeave 2.0 Language FundamentalsDataWeave 2.0 Language Fundamentals
DataWeave 2.0 Language Fundamentals
 
Introduction to Integration Testing With Cypress
Introduction to Integration Testing With CypressIntroduction to Integration Testing With Cypress
Introduction to Integration Testing With Cypress
 
"Crafting a Third-Party Banking Library with Web Components and React", Germa...
"Crafting a Third-Party Banking Library with Web Components and React", Germa..."Crafting a Third-Party Banking Library with Web Components and React", Germa...
"Crafting a Third-Party Banking Library with Web Components and React", Germa...
 
Responsive, adaptive and responsible - keynote at NebraskaJS
Responsive, adaptive and responsible - keynote at NebraskaJSResponsive, adaptive and responsible - keynote at NebraskaJS
Responsive, adaptive and responsible - keynote at NebraskaJS
 
Asynchronous javascript
 Asynchronous javascript Asynchronous javascript
Asynchronous javascript
 
#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange
#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange
#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange
 
GraphQL Bangkok Meetup 6.0
GraphQL Bangkok Meetup 6.0GraphQL Bangkok Meetup 6.0
GraphQL Bangkok Meetup 6.0
 
Tips for Building your First XPages Java Application
Tips for Building your First XPages Java ApplicationTips for Building your First XPages Java Application
Tips for Building your First XPages Java Application
 
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
AD113  Speed Up Your Applications w/ Nginx and PageSpeedAD113  Speed Up Your Applications w/ Nginx and PageSpeed
AD113 Speed Up Your Applications w/ Nginx and PageSpeed
 
Gatsby vs. Next.js
Gatsby vs. Next.jsGatsby vs. Next.js
Gatsby vs. Next.js
 
Unit testing legacy code
Unit testing legacy codeUnit testing legacy code
Unit testing legacy code
 
Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!
 
The 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for JavaThe 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for Java
 
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
 

Más de Geshan Manandhar

Drupal 7 basic setup and contrib modules for a brochure website
Drupal 7 basic setup and contrib modules for a brochure websiteDrupal 7 basic setup and contrib modules for a brochure website
Drupal 7 basic setup and contrib modules for a brochure website
Geshan Manandhar
 
Drupal 7 install with modules and themes
Drupal 7 install with modules and themesDrupal 7 install with modules and themes
Drupal 7 install with modules and themes
Geshan Manandhar
 
Business Rules Logical Experssion and SBVR
Business Rules Logical Experssion and SBVRBusiness Rules Logical Experssion and SBVR
Business Rules Logical Experssion and SBVR
Geshan Manandhar
 

Más de Geshan Manandhar (20)

Are logs a software engineer’s best friend? Yes -- follow these best practices
Are logs a software engineer’s best friend? Yes -- follow these best practicesAre logs a software engineer’s best friend? Yes -- follow these best practices
Are logs a software engineer’s best friend? Yes -- follow these best practices
 
Moving from A and B to 150 microservices, the journey, and learnings
Moving from A and B to 150 microservices, the journey, and learningsMoving from A and B to 150 microservices, the journey, and learnings
Moving from A and B to 150 microservices, the journey, and learnings
 
Adopt a painless continuous delivery culture, add more business value
Adopt a painless continuous delivery culture, add more business valueAdopt a painless continuous delivery culture, add more business value
Adopt a painless continuous delivery culture, add more business value
 
Things i wished i knew as a junior developer
Things i wished i knew as a junior developerThings i wished i knew as a junior developer
Things i wished i knew as a junior developer
 
Embrace chatops, stop installing deployment software - Laracon EU 2016
Embrace chatops, stop installing deployment software - Laracon EU 2016Embrace chatops, stop installing deployment software - Laracon EU 2016
Embrace chatops, stop installing deployment software - Laracon EU 2016
 
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
 
Embrace chatOps, stop installing deployment software
Embrace chatOps, stop installing deployment softwareEmbrace chatOps, stop installing deployment software
Embrace chatOps, stop installing deployment software
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
 
Software engineering In Nepal mid 2015 part 01
Software engineering In Nepal mid 2015 part 01Software engineering In Nepal mid 2015 part 01
Software engineering In Nepal mid 2015 part 01
 
A simplified Gitflow
A simplified GitflowA simplified Gitflow
A simplified Gitflow
 
How to become a better software company technically
How to become a better software company technicallyHow to become a better software company technically
How to become a better software company technically
 
Things I wished I knew while doing my tech bachelor / undergraduate
Things I wished I knew while doing my tech bachelor / undergraduateThings I wished I knew while doing my tech bachelor / undergraduate
Things I wished I knew while doing my tech bachelor / undergraduate
 
Message Queues a basic overview
Message Queues a basic overviewMessage Queues a basic overview
Message Queues a basic overview
 
Most popular brands, people on facebook in nepal as of 2013 q4
Most popular brands, people on facebook in nepal as of 2013 q4Most popular brands, people on facebook in nepal as of 2013 q4
Most popular brands, people on facebook in nepal as of 2013 q4
 
Drupal 7 basic setup and contrib modules for a brochure website
Drupal 7 basic setup and contrib modules for a brochure websiteDrupal 7 basic setup and contrib modules for a brochure website
Drupal 7 basic setup and contrib modules for a brochure website
 
Git intro hands on windows with msysgit
Git intro hands on windows with msysgitGit intro hands on windows with msysgit
Git intro hands on windows with msysgit
 
Drupal 7 install with modules and themes
Drupal 7 install with modules and themesDrupal 7 install with modules and themes
Drupal 7 install with modules and themes
 
Drupal introduction
Drupal introductionDrupal introduction
Drupal introduction
 
No sql
No sqlNo sql
No sql
 
Business Rules Logical Experssion and SBVR
Business Rules Logical Experssion and SBVRBusiness Rules Logical Experssion and SBVR
Business Rules Logical Experssion and SBVR
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 

We lost $ 20.5K in one day and how we could have saved it… hint: better automated testing

  • 1. @geshan We lost $ 20.5K in one day and how we could have saved it… hint: better automated testing Geshan Manandhar Senior Software Engineer (THE ICONIC)
  • 2. @geshan whoami ▪ Senior Software Engineer ▫ Tech Solution provider ▪ Agile follower ▪ Conditional microservices believer 2
  • 3. I am from Kathmandu, Nepal
  • 4. I was working for a GFG venture in Middle East
  • 5. Now I work at THE ICONIC
  • 6. @geshan One day early 2017 we deployed a new app rewrite and lost 20.5 K USD in ~24 hours? How? With 5 or less lines of code 6
  • 7. @geshan These 5 lines of code return isFirstShipmentofOrder(connection, orderData.fk_sales_order).then(isFirstShipment => { isFirstShipment = isFirstShipment[0]; //this was always false let serviceFee = isFirstShipment ? parseFloat(orderData.shipping_amount) + parseFloat(orderData.payment_fees) : 0; //so this was always 0 … }7
  • 8. @geshan Not blaming anyone ▪ Mysql2 library was not the 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
  • 9. @geshan9 End of Story => Start of the tutorial
  • 10. @geshan10 Most tech tutorials be like (probably not this one, not sure)
  • 11. @geshan This talk is about testing not the story ▪ 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
  • 12. @geshan Minimalist approach (opinionated) ▪ Using assert (not chai) - 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
  • 13. @geshan Currency Converter API ▪ Let's start with a simple 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
  • 15. @geshan Conclusion ▪ Write tests for confidence not 100% code 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
  • 17. @geshan THANKS! Any questions? You can find me at @geshan and Geshan.com.np Slides at: http://bit.ly/testing-nodejs 17