Total Complexity | 1 |
Complexity/F | 0 |
Lines of Code | 36 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { getExchangeRate } from '../src' |
||
2 | |||
3 | const shouldRunAcceptanceTests = process.env.RUN_ACCEPTANCE_TESTS === 'true' |
||
4 | const runOrSkip = shouldRunAcceptanceTests ? describe : describe.skip |
||
5 | runOrSkip('getExchangeRate acceptance tests', () => { |
||
6 | |||
7 | jest.setTimeout(30 * 1000) |
||
8 | |||
9 | it('should return exchange rate for real API call', async () => { |
||
10 | const rate = await getExchangeRate('USD', 'EUR') |
||
11 | |||
12 | console.log(`1 USD = ${rate} EUR`) |
||
13 | expect(rate).toBeGreaterThan(0) // Basic check, as the actual rate will vary |
||
14 | }) |
||
15 | |||
16 | it('should handle requests for multiple currency pairs', async () => { |
||
17 | const rates = await Promise.all([ |
||
18 | getExchangeRate('USD', 'EUR'), |
||
19 | getExchangeRate('USD', 'GBP'), |
||
20 | getExchangeRate('USD', 'JPY'), |
||
21 | ]) |
||
22 | |||
23 | console.log(`1 USD = ${rates[0]} EUR`) |
||
24 | console.log(`1 USD = ${rates[1]} GBP`) |
||
25 | console.log(`1 USD = ${rates[2]} JPY`) |
||
26 | |||
27 | rates.forEach(rate => { |
||
28 | expect(rate).toBeGreaterThan(0) |
||
29 | }) |
||
30 | }) |
||
31 | |||
32 | it('should throw an error for unknown currency codes', async () => { |
||
33 | await expect(getExchangeRate('USD', 'ZZZ')).rejects.toThrow() |
||
34 | }) |
||
35 | }) |
||
36 |