All Projects → geshan → currency-api

geshan / currency-api

Licence: other
A demo project on how to test a node/express app with Mocha, Nock and proxyquire (MNP) and code coverage with nyc/istanbul.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
Dockerfile
14818 projects
arc
50 projects

Projects that are alternatives of or similar to currency-api

playwright-test
Run unit tests with several runners or benchmark inside real browsers with playwright.
Stars: ✭ 81 (+326.32%)
Mutual labels:  nyc, mocha, istanbul
tropic
🍍 Test Runner Library
Stars: ✭ 29 (+52.63%)
Mutual labels:  unit-testing, mocha
awesome-javascript-testing
🔧 Awesome JavaScript testing resources
Stars: ✭ 28 (+47.37%)
Mutual labels:  unit-testing, mocha
Eth Gas Reporter
Gas usage per unit test. Average gas usage per method. A mocha reporter.
Stars: ✭ 330 (+1636.84%)
Mutual labels:  unit-testing, mocha
floss
Unit-testing for those hard to reach places
Stars: ✭ 26 (+36.84%)
Mutual labels:  unit-testing, mocha
Pg Mem
An in memory postgres DB instance for your unit tests
Stars: ✭ 350 (+1742.11%)
Mutual labels:  unit-testing, mocha
Sazerac
Data-driven unit testing for Jasmine, Mocha, and Jest
Stars: ✭ 322 (+1594.74%)
Mutual labels:  unit-testing, mocha
lisk-template
📄 Template repository for Lisk projects
Stars: ✭ 39 (+105.26%)
Mutual labels:  nyc, mocha
Snap Shot
Jest-like snapshot feature for the rest of us, works magically by finding the right caller function
Stars: ✭ 170 (+794.74%)
Mutual labels:  unit-testing, mocha
Redux Actions Assertions
Simplify testing of redux action and async action creators
Stars: ✭ 177 (+831.58%)
Mutual labels:  unit-testing, mocha
istanbul-badges-readme
Creates and updates README testing coverage badges with your json-summary
Stars: ✭ 77 (+305.26%)
Mutual labels:  nyc, istanbul
chai-exclude
Exclude keys to compare from a deep equal operation with chai expect or assert.
Stars: ✭ 33 (+73.68%)
Mutual labels:  unit-testing, mocha
jsish
Jsi is a small, C-embeddable javascript interpreter with tightly woven Web and DB support.
Stars: ✭ 32 (+68.42%)
Mutual labels:  unit-testing
kmtest
Kernel-mode C++ unit testing framework in BDD-style
Stars: ✭ 42 (+121.05%)
Mutual labels:  unit-testing
eat
Json based scenario testing tool(which can have test for functional and non-functional)
Stars: ✭ 41 (+115.79%)
Mutual labels:  unit-testing
ava-fast-check
Property based testing for AVA based on fast-check
Stars: ✭ 44 (+131.58%)
Mutual labels:  unit-testing
node-server-template
This is Node.js server tidy template / boilerplate with Express (with asyncified handlers, custom error handler) framework and MongoDb. The server use ES6 and above. On different branches you can see different techniques' and technologies' usage, such as Kafka, nodemailer, file download... You also can find postman collections.
Stars: ✭ 116 (+510.53%)
Mutual labels:  mocha
picolisp-unit
Unit Testing framework for PicoLisp
Stars: ✭ 22 (+15.79%)
Mutual labels:  unit-testing
gds-nodejs-boilerplate
A Node.js project boilerplate for production apps
Stars: ✭ 18 (-5.26%)
Mutual labels:  mocha
parse-server-test-runner
A tool for programmatically starting Parse Server
Stars: ✭ 18 (-5.26%)
Mutual labels:  mocha

Currency API

A simple project to show how to test a Node Express app using MNP - Mocha, Nock and Proxyquire. Code coverage is done with Istanbul (now called nyc). Rewire can be used in place of proxyquire to test private JS methods. This app is a very basic currency API.

Build Status Maintainability Test Coverage

Running app

You can see this app running on Zeit Now, each pull request will have it's own URL.

Run on Google cloud run

Run on Google Cloud

How it works

The GET api works in the following way:

  1. hit URL /api/convert/AUD/USD/2018-07-22.
  2. Checks if the currency exchange rate is in the DB, if yes returns it.
  3. If rate is not in the db it will query the currencyconverterapi.com free API to get the rate.
  4. Returns the rate back and saves it in the DB too.

DB script

To create the db and the table, run the following sql script.

CREATE DATABASE currency CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE TABLE IF NOT EXISTS `currency`.`exchange_rates` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `from_currency` CHAR(3) NOT NULL,
  `to_currency` CHAR(3) NOT NULL,
  `rate` DECIMAL(12,7) NOT NULL,
  `on_date` DATE NOT NULL,
  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `rate_on_date_UNIQUE` (`from_currency` ASC, `to_currency` ASC, `on_date` ASC))
ENGINE = InnoDB;

INSERT INTO `currency`.`exchange_rates` (`from_currency`, `to_currency`, `rate`, `on_date`) VALUES ('AUD', 'USD', '0.742719', '2018-07-22');

Configs

Configs for db like username, password etc are in the /src/config.js file.

Run

to run the app you can use docker-compose up the go to http://localhost:8080/api/convert/AUD/USD/2018-07-23 on the browser. It is using the db on remotemysql.com so no need to setup the db locally. If you want to set it up locally change the config in src/configs.js or put in environment variables.

Run tests

To run the tests inside the container run docker-compose run web npm t

To run tests just run npm t to watch test run npm t -- -w.

To watch specific test(s) run npm t -- -w -g "exchangeRates get or even npm t -- -w -g "should use default params if no params are provided and no results in db"

Code coverage

To get the code coverage with Istanbul/nyc execute : npm run test-cov. You should see the code coverage on the cli.

You can also check the code coverage on code climate.

Mutation testing

Has some mutation testing done with Stryker. Current coverage is ~88% with mostly log lines failing. To run the mutation tests run the following after installing stryker.

stryker run

or

npm run mutation-cov
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].