Skip to content

Commit 55645fc

Browse files
authored
Merge pull request #6 from vahidvdn/tests/unit-tests
Tests/unit tests
2 parents 492cafa + e2ffcd6 commit 55645fc

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## RELEASE 1.3.0
2+
### Feature
3+
* Add unit tests
4+
### Bug Fixes
5+
* Add support for full parsing
6+
17
## RELEASE 1.2.0
28
### Feature
39
* Better typing

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nestjs-cashify",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Currency conversion module for nest",
55
"author": "Vahid Najafi <[email protected]>",
66
"license": "MIT",
@@ -24,6 +24,8 @@
2424
"keywords": [
2525
"nestjs",
2626
"nodejs",
27+
"javascript",
28+
"typescript",
2729
"cashify",
2830
"nestjs-cashify",
2931
"currency-exchange",

src/cashify.service.spec.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Test } from '@nestjs/testing';
2+
import { Cashify } from 'cashify';
3+
import { CASHIFY, CashifyService } from './';
4+
5+
6+
describe('CashifyService', () => {
7+
8+
let cashifyService:CashifyService;
9+
const options = {
10+
base: 'EUR',
11+
rates: {
12+
GBP: 0.92,
13+
EUR: 1,
14+
USD: 1.12
15+
}
16+
};
17+
18+
beforeEach(async () => {
19+
const moduleRef = await Test.createTestingModule({
20+
providers: [
21+
CashifyService,
22+
{
23+
provide: CASHIFY,
24+
useValue: new Cashify(options),
25+
}
26+
],
27+
}).compile();
28+
29+
cashifyService = moduleRef.get<CashifyService>(CashifyService);
30+
});
31+
32+
it('should be defined', () => {
33+
expect(cashifyService).toBeDefined();
34+
})
35+
36+
it('should convert properly', () => {
37+
let converted = cashifyService.convert(12, {from: 'USD', to: 'GBP'});
38+
expect(converted).toEqual(9.857142857142856);
39+
})
40+
41+
it('should accept string amount', () => {
42+
let converted = cashifyService.convert('10', {from: 'EUR', to: 'GBP'});
43+
expect(converted).toEqual(9.2);
44+
})
45+
46+
it('should do basic parsing', () => {
47+
let converted = cashifyService.convert('€10 EUR', {to: 'GBP'});
48+
expect(converted).toEqual(9.2);
49+
})
50+
51+
it('should do full parsing', () => {
52+
let converted = cashifyService.convert('€10 EUR to GBP');
53+
expect(converted).toEqual(9.2);
54+
})
55+
})

src/cashify.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CASHIFY } from './';
66
export class CashifyService {
77
constructor(@Inject(CASHIFY) private readonly cashify: Cashify) {}
88

9-
public convert(amount, options) {
9+
public convert(amount, options?) {
1010
return this.cashify.convert(amount, options);
1111
}
1212
}

0 commit comments

Comments
 (0)