Fix incorrect usage of exchange rate API service #7
Open
opened 10 months ago by inga-lovinde
·
0 comments
Loading…
Reference in new issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
According to the README:
In
exchange-rate.dto.ts
, the following is hardcoded:and the requests are made in
exchange-rate.service.ts
byAdditionally, the return type is declared as
ExchangeRateResponse
, and is obtained bywhere
ExchangeRateResponse
is declared asAdditionally, it is then used in
transaction.controller.ts
asand it is mocked in
transaction.controller.spec.ts
asThere are multiple layers of problems here:
api.exchangerate.host
requires an API key which is not provided, so the request will fail with 403 or similar error;api.exchangerate.host
does not have endpoints of the form https://api.exchangerate.host/2021-01-01 ; what it does have is endpoints like https://api.exchangerate.host/historical?access_key=YOUR_ACCESS_KEY&date=2021-01-01success
,terms
,privacy
,historical
,date
,timestamp
, andsource
; and with dictionary fieldquote
, containing entries like"USDAED": 3.67266
. Yetexchange-rate.service.ts
is attempting to return a non-existent fieldaxiosResponse.data?.rates
.exchange-rate.dto.ts
, the service returns a complex structure, yettransaction.controller.ts
expects it to be a dictionary containing entries like"USD": 1.2
. In strict TS mode this would be a compiler error (trying to index a specific complex shape by an arbitrary string; trying to use the resulting value as a number), but most strict features of TS are disabled or not enabled intsconfig.json
, so this slips unnoticed;transaction.controller.spec.ts
mocks exchange rate service to return whattransaction.controller.ts
expects, not whatexchange-rate.service.ts
is declared to return;"USD": 1.2
seems to mean that one USD is worth 0.8(6) EUR, which is odd (and also, why is the base currency of exchange service EUR, if we don't pass any currencies to it?)The entire part of the code around currency conversion is broken, the only way to fix it is to rewrite it.