Skip to content

Commit

Permalink
Added more currencies
Browse files Browse the repository at this point in the history
More test cases to sanity check fiat currencies
  • Loading branch information
chill117 committed Oct 14, 2023
1 parent 6bdb294 commit 839bc77
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 19 deletions.
126 changes: 119 additions & 7 deletions lib/fiatCurrencies.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
[
{
"fiatCurrency": "AUD",
"coinValues": [0.05, 0.1, 0.2, 0.5, 1, 2],
"coinValueIncrement": 0.05,
"billValues": [5, 10, 20, 50, 100],
"fiatPrecision": 2,
"buyLimit": 400
},
{
"fiatCurrency": "BGN",
"coinValues": [0.05, 0.1, 0.25, 0.5, 1],
Expand All @@ -13,47 +21,47 @@
"coinValueIncrement": 0.05,
"billValues": [2, 5, 10, 20, 50, 100, 200],
"fiatPrecision": 2,
"buyLimit": 1250
"buyLimit": 1300
},
{
"fiatCurrency": "CAD",
"coinValues": [0.05, 0.1, 0.25, 0.5, 1],
"coinValueIncrement": 0.05,
"billValues": [5, 10, 20, 50, 100],
"fiatPrecision": 2,
"buyLimit": 300
"buyLimit": 350
},
{
"fiatCurrency": "CHF",
"coinValues": [0.1, 0.2, 0.5, 1, 2, 5],
"coinValueIncrement": 0.1,
"billValues": [10, 20, 50, 100, 200],
"fiatPrecision": 2,
"buyLimit": 250
"buyLimit": 500
},
{
"fiatCurrency": "CLP",
"coinValues": [50, 100, 500],
"coinValueIncrement": 50,
"billValues": [1000, 2000, 5000, 10000, 20000],
"fiatPrecision": 0,
"buyLimit": 200000
"buyLimit": 250000
},
{
"fiatCurrency": "COP",
"coinValues": [50, 100, 500, 1000],
"coinValueIncrement": 50,
"billValues": [1000, 2000, 5000, 10000, 20000, 50000, 100000],
"fiatPrecision": 0,
"buyLimit": 800000
"buyLimit": 1000000
},
{
"fiatCurrency": "CZK",
"coinValues": [1, 2, 5, 10, 20, 50],
"coinValueIncrement": 1,
"billValues": [100, 200, 500, 1000, 2000],
"fiatPrecision": 0,
"buyLimit": 5000
"buyLimit": 6000
},
{
"fiatCurrency": "DKK",
Expand All @@ -77,7 +85,7 @@
"coinValueIncrement": 0.1,
"billValues": [5, 10, 20, 50],
"fiatPrecision": 2,
"buyLimit": 200
"buyLimit": 250
},
{
"fiatCurrency": "HRK",
Expand All @@ -95,6 +103,62 @@
"fiatPrecision": 0,
"buyLimit": 100000
},
{
"fiatCurrency": "INR",
"coinValues": [1, 2, 5, 10],
"coinValueIncrement": 1,
"billValues": [10, 20, 50, 100, 200, 500],
"fiatPrecision": 0,
"buyLimit": 15000
},
{
"fiatCurrency": "ISK",
"coinValues": [5, 10, 50, 100],
"coinValueIncrement": 5,
"billValues": [500, 1000, 2000, 5000, 10000],
"fiatPrecision": 0,
"buyLimit": 40000
},
{
"fiatCurrency": "JMD",
"coinValues": [5, 10, 20],
"coinValueIncrement": 5,
"billValues": [50, 100, 500, 1000, 2000],
"fiatPrecision": 0,
"buyLimit": 30000
},
{
"fiatCurrency": "JPY",
"coinValues": [5, 10, 50, 100, 500],
"coinValueIncrement": 5,
"billValues": [1000, 5000, 10000],
"fiatPrecision": 0,
"buyLimit": 50000
},
{
"fiatCurrency": "KRW",
"coinValues": [10, 50, 100, 500],
"coinValueIncrement": 10,
"billValues": [1000, 5000, 10000, 50000],
"fiatPrecision": 0,
"buyLimit": 400000
},
{
"fiatCurrency": "MAD",
"coinValues": [0.2, 0.5, 1, 2, 5, 10],
"coinValueIncrement": 0.1,
"billValues": [20, 50, 100, 200],
"fiatPrecision": 2,
"buyLimit": 2000
},
{
"fiatCurrency": "MKD",
"coinValues": [1, 2, 5, 10, 50],
"coinValueIncrement": 1,
"billValues": [50, 100, 200, 500, 1000, 2000],
"fiatPrecision": 0,
"buyLimit": 16000
},
{
"fiatCurrency": "MXN",
"coinValues": [0.5, 1, 2, 5, 10],
Expand All @@ -103,6 +167,14 @@
"fiatPrecision": 2,
"buyLimit": 5000
},
{
"fiatCurrency": "NGN",
"coinValues": [0.5, 1, 2],
"coinValueIncrement": 0.5,
"billValues": [20, 50, 100, 200, 500, 1000],
"fiatPrecision": 2,
"buyLimit": 150000
},
{
"fiatCurrency": "NOK",
"coinValues": [1, 5, 10, 20],
Expand All @@ -111,6 +183,14 @@
"fiatPrecision": 0,
"buyLimit": 2500
},
{
"fiatCurrency": "NZD",
"coinValues": [0.1, 0.2, 0.5, 1, 2],
"coinValueIncrement": 0.1,
"billValues": [5, 10, 20, 50, 100],
"fiatPrecision": 2,
"buyLimit": 450
},
{
"fiatCurrency": "PEN",
"coinValues": [0.1, 0.2, 0.5, 1, 2, 5],
Expand All @@ -119,6 +199,14 @@
"fiatPrecision": 2,
"buyLimit": 1000
},
{
"fiatCurrency": "PHP",
"coinValues": [1, 5, 10, 20],
"coinValueIncrement": 1,
"billValues": [20, 50, 100, 500, 1000],
"fiatPrecision": 0,
"buyLimit": 12000
},
{
"fiatCurrency": "PLN",
"coinValues": [0.1, 0.2, 0.5, 1, 2, 5],
Expand Down Expand Up @@ -151,6 +239,14 @@
"fiatPrecision": 0,
"buyLimit": 2500
},
{
"fiatCurrency": "SGD",
"coinValues": [0.05, 0.1, 0.2, 0.5, 1],
"coinValueIncrement": 0.05,
"billValues": [2, 5, 10, 50, 100],
"fiatPrecision": 2,
"buyLimit": 400
},
{
"fiatCurrency": "TRY",
"coinValues": [0.05, 0.1, 0.25, 0.5, 1],
Expand All @@ -166,5 +262,21 @@
"billValues": [1, 5, 10, 20, 50, 100],
"fiatPrecision": 2,
"buyLimit": 250
},
{
"fiatCurrency": "VND",
"coinValues": [],
"coinValueIncrement": 1,
"billValues": [5000, 10000, 20000, 50000, 100000, 200000],
"fiatPrecision": 0,
"buyLimit": 2000000
},
{
"fiatCurrency": "ZAR",
"coinValues": [0.1, 0.2, 0.5, 1, 2, 5],
"coinValueIncrement": 0.1,
"billValues": [10, 20, 50, 100, 200],
"fiatPrecision": 2,
"buyLimit": 3000
}
]
71 changes: 59 additions & 12 deletions test/unit/lib/fiatCurrencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,67 @@ const { fiatCurrencies } = require('../../../');

describe('fiatCurrencies', function() {

it('sanity check', function() {
it('sanity checks', function() {
assert.ok(fiatCurrencies instanceof Array);
assert.ok(fiatCurrencies.length > 0);
fiatCurrencies.forEach((item, index) => {
assert.strictEqual(typeof item, 'object');
const { fiatCurrency } = item;
assert.ok(fiatCurrency, `Missing currency symbol ("fiatCurrency"): index = ${index}`);
assert.strictEqual(fiatCurrency.length, 3, `Fiat currency symbol must be exactly 3 characters: fiatCurrency = "${fiatCurrency}"`);
assert.strictEqual(fiatCurrency, fiatCurrency.replace(/[^A-Z]/g, ''), `Fiat currency symbol must contain only uppercase alphabetic characters: fiatCurrency = "${fiatCurrency}"`);
assert.ok(item.coinValues, `Missing "coinValues" for fiat currency where fiatCurrency = ${fiatCurrency}`);
assert.ok(item.coinValueIncrement, `Missing "coinValueIncrement" for fiat currency where fiatCurrency = ${fiatCurrency}`);
assert.ok(item.billValues, `Missing "billValues" for fiat currency where fiatCurrency = ${fiatCurrency}`);
assert.notStrictEqual(typeof item.fiatPrecision, 'undefined', `Missing "fiatPrecision" for fiat currency where fiatCurrency = ${fiatCurrency}`);
assert.ok(item.buyLimit, `Missing "buyLimit" for fiat currency where fiatCurrency = ${fiatCurrency}`);
});

fiatCurrencies.forEach((item, index) => {

const { fiatCurrency } = item || {};

describe(`"${fiatCurrency}" (index = ${index})`, function() {

describe('fiatCurrency symbol', function() {
it('is exactly 3 characters', function() {
assert.strictEqual(fiatCurrency.length, 3);
});
it('contains only uppercase alphabetic characters', function() {
assert.strictEqual(fiatCurrency, fiatCurrency.replace(/[^A-Z]/g, ''));
});
});

['fiatCurrency', 'coinValues', 'coinValueIncrement', 'billValues', 'fiatPrecision', 'buyLimit'].forEach(key => {
it(`"${key}" is defined`, function() {
assert.notStrictEqual(typeof item[key], 'undefined');
});
});

['coinValues', 'billValues'].forEach(key => {
describe(key, function() {
it('is an array of numbers', function() {
assert.ok(item[key] instanceof Array);
item[key].forEach(value => {
assert.ok(!Number.isNaN(parseFloat(value)));
});
});
it('is in ascending order', function() {
item[key].forEach((value, index) => {
assert.ok(index === 0 || value > item[key][index - 1]);
});
});
});
});

['coinValueIncrement', 'buyLimit'].forEach(key => {
it(`"${key}" is a number`, function() {
assert.ok(!Number.isNaN(parseFloat(item[key])));
});
});

['fiatPrecision'].forEach(key => {
it(`"${key}" is an integer`, function() {
assert.ok(Number.isInteger(item[key]));
});
});

it('all numbers in "coinValues" are divisible by "coinValueIncrement"', function() {
const multiplier = Math.pow(10, item.fiatPrecision);
const increment = item.coinValueIncrement * multiplier;
item.coinValues.forEach((value, index) => {
assert.ok((value * multiplier) % increment === 0);
});
});
});
});
});

0 comments on commit 839bc77

Please sign in to comment.