{"id":16463339,"url":"https://github.com/geshan/currency-api","last_synced_at":"2025-03-16T18:31:25.120Z","repository":{"id":40661064,"uuid":"151711858","full_name":"geshan/currency-api","owner":"geshan","description":"A demo project on how to test a node/express app with Mocha, Nock and proxyquire (MNP) and code coverage with nyc/istanbul.","archived":false,"fork":false,"pushed_at":"2025-03-13T08:04:02.000Z","size":3499,"stargazers_count":19,"open_issues_count":13,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-13T09:19:44.848Z","etag":null,"topics":["example","express","istanbul","javascript","mocha","nock","nodejs","nyc","proxyquire","testing","unit-testing"],"latest_commit_sha":null,"homepage":"https://currency-api.geshanm.now.sh","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geshan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-05T11:37:10.000Z","updated_at":"2025-03-13T08:04:03.000Z","dependencies_parsed_at":"2023-02-10T11:15:59.897Z","dependency_job_id":"ad2e907b-6815-40d2-853f-a24313adc097","html_url":"https://github.com/geshan/currency-api","commit_stats":{"total_commits":189,"total_committers":10,"mean_commits":18.9,"dds":0.5978835978835979,"last_synced_commit":"1be0b9c3c487d55116b968ccd8b611a0186f2f4c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geshan%2Fcurrency-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geshan%2Fcurrency-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geshan%2Fcurrency-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geshan%2Fcurrency-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geshan","download_url":"https://codeload.github.com/geshan/currency-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243826788,"owners_count":20354220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example","express","istanbul","javascript","mocha","nock","nodejs","nyc","proxyquire","testing","unit-testing"],"created_at":"2024-10-11T11:14:11.371Z","updated_at":"2025-03-16T18:31:24.459Z","avatar_url":"https://github.com/geshan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Currency API\n\nA simple project to show how to test a Node Express app using MNP - Mocha, Nock and Proxyquire.\nCode coverage is done with Istanbul (now called nyc). Rewire can be used in place of\nproxyquire to test private JS methods. This app is a very basic currency API.\n\n[![Build Status](https://travis-ci.org/geshan/currency-api.svg?branch=master)](https://travis-ci.org/geshan/currency-api) [![Maintainability](https://api.codeclimate.com/v1/badges/54eef9745fdb3b5c5476/maintainability)](https://codeclimate.com/github/geshan/currency-api/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/54eef9745fdb3b5c5476/test_coverage)](https://codeclimate.com/github/geshan/currency-api/test_coverage) \n\n## Running app\n\nYou can see this app running on [Zeit Now](https://currency-api.geshanm.now.sh/api/convert/USD/AUD/2019-08-05), each pull request will have it's own URL.\n\n## Run on Google cloud run\n\n[![Run on Google Cloud](https://storage.googleapis.com/cloudrun/button.svg)](https://console.cloud.google.com/cloudshell/editor?shellonly=true\u0026cloudshell_image=gcr.io/cloudrun/button\u0026cloudshell_git_repo=https://github.com/geshan/currency-api.git)\n\n## How it works\n\nThe `GET` api works in the following way:\n\n1. hit URL `/api/convert/AUD/USD/2018-07-22`.\n1. Checks if the currency exchange rate is in the DB, if yes returns it.\n1. If rate is not in the db it will query the `currencyconverterapi.com` free API to get the rate.\n1. Returns the rate back and saves it in the DB too.\n\n## DB script\n\nTo create the db and the table, run the following sql script.\n\n```\nCREATE DATABASE currency CHARACTER SET utf8 COLLATE utf8_general_ci;\nCREATE TABLE IF NOT EXISTS `currency`.`exchange_rates` (\n  `id` INT NOT NULL AUTO_INCREMENT,\n  `from_currency` CHAR(3) NOT NULL,\n  `to_currency` CHAR(3) NOT NULL,\n  `rate` DECIMAL(12,7) NOT NULL,\n  `on_date` DATE NOT NULL,\n  `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,\n  PRIMARY KEY (`id`),\n  UNIQUE INDEX `rate_on_date_UNIQUE` (`from_currency` ASC, `to_currency` ASC, `on_date` ASC))\nENGINE = InnoDB;\n\nINSERT INTO `currency`.`exchange_rates` (`from_currency`, `to_currency`, `rate`, `on_date`) VALUES ('AUD', 'USD', '0.742719', '2018-07-22');\n\n```\n\n## Configs\n\nConfigs for db like username, password etc are in the `/src/config.js` file.\n\n## Run\n\nto 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.\n\n## Run tests\n\nTo run the tests inside the container run `docker-compose run web npm t`\n\nTo run tests just run `npm t` to watch test run `npm t -- -w`.\n\nTo watch specific test(s) run `npm t -- -w -g \"exchangeRates get` or even\n`npm t -- -w -g \"should use default params if no params are provided and no results in db\"`\n\n### Code coverage\n\nTo get the code coverage with Istanbul/nyc execute : `npm run test-cov`. You should see the code coverage on the cli.\n\nYou can also check the code coverage on [code climate](https://codeclimate.com/github/geshan/currency-api/src/exchangeRates.js/source).\n\n### Mutation testing\n\nHas some mutation testing done with [Stryker](https://stryker-mutator.io/stryker/quickstart). Current\ncoverage is ~88% with mostly log lines failing. To run the mutation tests run the following after\ninstalling stryker.\n\n```bash\nstryker run\n\nor\n\nnpm run mutation-cov\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeshan%2Fcurrency-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeshan%2Fcurrency-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeshan%2Fcurrency-api/lists"}