The goal of this example is to write and test code to compute the value of a wallet containing different currencies in a given currency in typescript. We will run mocha and cucumber/gherkin unit tests on this code.
Choosen language:
Written and tested on nodejs: v12.22.6 aka. lts/erbium
npm install
Go to https://exchangeratesapi.io/, create an account and then copy the api key in a .env
at the root of the project such as:
API_KEY=74f1cf.....
npm run build
builds the ts into js to ./build
npm run test:unit
launches unit tests
npm run test:cucumber
launches cucumber tests on the features in ./features/...
async function computeWalletValue(wallet: Wallet, returnValueCurrency: Currencies = Currencies.EUR, date: string = 'latest'): Promise<number>
Possible currencies: CAD HKD ISK PHP DKK HUF CZK AUD RON SEK IDR INR BRL RUB HRK JPY THB CHF SGD PLN BGN TRY CNY NOK NZD ZAR USD MXN ILS GBP KRW MYR
Check-out our unit test: ./test/test.js
, for an example of how to call the function or run it by using npm run test:unit