currency-converter-lt
Advanced tools
Comparing version
@@ -217,2 +217,4 @@ const cheerio = require("cheerio") | ||
.then((rates) => { | ||
if(rates.includes(",")) | ||
rates = rates.replace(",", ".") | ||
return parseFloat(rates) | ||
@@ -254,6 +256,1 @@ }) | ||
module.exports = CurrencyConverter | ||
// let cc = new CurrencyConverter() | ||
// // console.log(cc.currencies) | ||
// cc.from("USD").to("BDT").convert().then((t) =>console.log(t)) | ||
// console.log(cc.currencyAmount) |
{ | ||
"name": "currency-converter-lt", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "A nodejs currency converter library that doesn't require subscribing to any API calls.", | ||
@@ -8,10 +8,10 @@ "main": "index.js", | ||
"cheerio": "^1.0.0-rc.5", | ||
"got": "^11.8.1" | ||
"got": "^11.8.2" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.3.0", | ||
"chai-as-promised": "^7.1.1", | ||
"codecov": "^3.8.1", | ||
"mocha": "^8.3.0", | ||
"nyc": "^15.1.0" | ||
"chai": "latest", | ||
"chai-as-promised": "latest", | ||
"codecov": "latest", | ||
"mocha": "latest", | ||
"nyc": "latest" | ||
}, | ||
@@ -18,0 +18,0 @@ "scripts": { |
const chai = require("chai") | ||
const assert = chai.assert | ||
const expect = chai.expect | ||
const chaiAsPromised = require("chai-as-promised"); | ||
chai.use(chaiAsPromised); | ||
const chaiAsPromised = require("chai-as-promised") | ||
// const chaiJestMock = require('chai-jest-mocks') | ||
chai.use(chaiAsPromised) | ||
// chai.use(chaiJestMock) | ||
const CC = require("../index.js") | ||
@@ -11,5 +14,5 @@ | ||
describe("currencyConverter", function () { | ||
describe("constructor", function () { | ||
it("should instantiate an object without parameters", function () { | ||
describe("currencyConverter", () => { | ||
describe("constructor", () => { | ||
it("should instantiate an object without parameters", () => { | ||
let CC_ = new CC() | ||
@@ -19,3 +22,3 @@ assert.equal(CC_.currencyFrom, "") | ||
it("should instantiate an object with json object as a parameter", function () { | ||
it("should instantiate an object with json object as a parameter", () => { | ||
let CC_ = new CC({from:"GBP", to:"CAD", amount: 100}) | ||
@@ -25,3 +28,3 @@ assert.equal(CC_.currencyFrom, "GBP") | ||
it("should instantiate an object with json object with partial parameters", function () { | ||
it("should instantiate an object with json object with partial parameters", () => { | ||
let CC_ = new CC({from:"GBP", amount: 100}) | ||
@@ -40,3 +43,3 @@ assert.equal(CC_.currencyFrom, "GBP") | ||
it("should throw a TypeError", function () { | ||
it("should throw a TypeError", () => { | ||
expect(() => new CC({from:20, amount: 100})).to.throw(TypeError) | ||
@@ -46,4 +49,4 @@ }) | ||
describe("currencyFrom", function () { | ||
it("should equal to USD", function () { | ||
describe("currencyFrom", () => { | ||
it("should equal to USD", () => { | ||
currencyConverter.currencyFrom = "USD" | ||
@@ -53,3 +56,3 @@ assert.equal(currencyConverter.currencyFrom, "USD") | ||
it("should equal to INR", function () { | ||
it("should equal to INR", () => { | ||
currencyConverter.from("INR") | ||
@@ -59,7 +62,7 @@ assert.equal(currencyConverter.currencyFrom, "INR") | ||
it("should throw a TypeError", function () { | ||
it("should throw a TypeError", () => { | ||
expect(() => currencyConverter.from(5)).to.throw(TypeError); | ||
}) | ||
it("should throw an Error", function () { | ||
it("should throw an Error", () => { | ||
expect(() => currencyConverter.from("UDD")).to.throw(Error); | ||
@@ -70,4 +73,4 @@ }) | ||
describe("currencyTo", function () { | ||
it("should equal to CAD", function () { | ||
describe("currencyTo", () => { | ||
it("should equal to CAD", () => { | ||
currencyConverter.currencyTo = "CAD" | ||
@@ -77,3 +80,3 @@ assert.equal(currencyConverter.currencyTo, "CAD"); | ||
it("should equal to JPY", function () { | ||
it("should equal to JPY", () => { | ||
currencyConverter.to("JPY") | ||
@@ -83,7 +86,7 @@ assert.equal(currencyConverter.currencyTo, "JPY"); | ||
it("should throw a TypeError", function () { | ||
it("should throw a TypeError", () => { | ||
expect(() => currencyConverter.to(5)).to.throw(TypeError); | ||
}) | ||
it("should throw an Error", function () { | ||
it("should throw an Error", () => { | ||
expect(() => currencyConverter.to("UDD")).to.throw(Error); | ||
@@ -93,4 +96,4 @@ }) | ||
describe("currencyAmount", function () { | ||
it("should equal to 10", function () { | ||
describe("currencyAmount", () => { | ||
it("should equal to 10", () => { | ||
currencyConverter.amount(10) | ||
@@ -100,7 +103,7 @@ assert.equal(currencyConverter.currencyAmount, 10); | ||
it("should throw TypeError", function () { | ||
it("should throw TypeError", () => { | ||
expect(() => currencyConverter.amount("10")).to.throw(TypeError); | ||
}) | ||
it("should throw an Error", function () { | ||
it("should throw an Error", () => { | ||
expect(() => currencyConverter.amount(-1)).to.throw(Error); | ||
@@ -110,9 +113,11 @@ }) | ||
describe("rates", function () { | ||
currencyConverter.from("USD").to("JPY") | ||
return expect(currencyConverter.rates()).to.eventually.not.equal(undefined) | ||
describe("rates", () => { | ||
it("should not return undefined values", () => { | ||
currencyConverter.from("USD").to("JPY") | ||
return expect(currencyConverter.rates()).to.eventually.not.equal(undefined) | ||
}) | ||
}) | ||
describe("convert", function () { | ||
it("should set the amount value if a paramter is passed", function(){ | ||
describe("convert", () => { | ||
it("should set the amount value if a paramter is passed", () => { | ||
currencyConverter.from("USD").to("USD") | ||
@@ -122,3 +127,3 @@ return expect(currencyConverter.convert(100)).to.eventually.equal(100) | ||
it("should throw an Error", function () { | ||
it("should throw an Error", () => { | ||
currencyConverter.currencyFrom = "" | ||
@@ -129,3 +134,3 @@ currencyConverter.to("CAD").amount(100) | ||
it("should throw an Error", function () { | ||
it("should throw an Error", () => { | ||
currencyConverter.currencyTo = "" | ||
@@ -136,3 +141,3 @@ currencyConverter.from("CAD").amount(100) | ||
it("should throw an Error", function () { | ||
it("should throw an Error", () => { | ||
currencyConverter.currencyAmount = 0 | ||
@@ -144,12 +149,12 @@ currencyConverter.from("USD").to("CAD") | ||
describe("currencyName", function () { | ||
it("should return name of the currency from the currency code", function () { | ||
describe("currencyName", () => { | ||
it("should return name of the currency from the currency code", () => { | ||
assert.equal(currencyConverter.currencyName("CHF"), "Swiss Franc") | ||
}) | ||
it("should throw a TypeError", function () { | ||
it("should throw a TypeError", () => { | ||
expect(() => currencyConverter.currencyName(5)).to.throw(TypeError); | ||
}) | ||
it("should throw an Error", function () { | ||
it("should throw an Error", () => { | ||
expect(() => currencyConverter.currencyName("DDD")).to.throw(Error); | ||
@@ -156,0 +161,0 @@ }) |
Sorry, the diff of this file is not supported yet
20597
-2.66%8
-11.11%353
-3.02%Updated