-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tests): update test to use stubbed turbo client
We allow a TurboAuthenticatedClient as an optional constructor param for the TurboRatesOracle. This allows us to stub the client for tests, and validate the reponse returned from the SDK is what we return from our wrapper class.
- Loading branch information
dtfiedler
committed
Nov 16, 2023
1 parent
d001c08
commit 817f7d1
Showing
2 changed files
with
40 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,49 @@ | ||
import chai, { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import type { FiatID } from './fiat_oracle_types'; | ||
import { TurboRatesOracle } from './turbo_rates_oracle'; | ||
import { beforeEach, describe, it } from 'vitest'; | ||
import { | ||
TurboUnauthenticatedClient, | ||
TurboRatesResponse | ||
} from '@ardrive/turbo-sdk'; | ||
|
||
chai.use(chaiAsPromised); | ||
const turboStubbedResponse: TurboRatesResponse = { | ||
winc: '10000', | ||
fiat: { | ||
aud: 10.123, | ||
brl: 10.123, | ||
cad: 10.123, | ||
eur: 10.123, | ||
gbp: 10.123, | ||
hkd: 10.123, | ||
inr: 10.123, | ||
jpy: 10.123, | ||
sgd: 10.123, | ||
usd: 10.123 | ||
}, | ||
adjustments: [] | ||
}; | ||
|
||
const fiat: FiatID = 'usd'; | ||
const examplePriceValue = 15.05; | ||
chai.use(chaiAsPromised); | ||
|
||
const TurboRatesResponseSample = `{ | ||
"winc": 1, | ||
"fiat": { | ||
"${fiat}": ${examplePriceValue} | ||
} | ||
}`; | ||
describe('The TurboRatesOracle class', () => { | ||
let turboRatesOracle: TurboRatesOracle; | ||
let turboSpy: TurboUnauthenticatedClient; | ||
|
||
beforeEach(() => { | ||
turboRatesOracle = new TurboRatesOracle(); | ||
turboSpy = sinon.createStubInstance(TurboUnauthenticatedClient, { | ||
getFiatRates: Promise.resolve(turboStubbedResponse) | ||
}); | ||
turboRatesOracle = new TurboRatesOracle(turboSpy); | ||
}); | ||
|
||
describe('getFiatRatesForToken function', () => { | ||
it('returns the expected response after a single fetch', async () => { | ||
expect(await turboRatesOracle.getTurboRates()).to.deep.equal( | ||
TurboRatesResponseSample | ||
); | ||
it('returns the expected response from turbo', async () => { | ||
const rates = await turboRatesOracle.getTurboRates(); | ||
expect(rates).to.deep.equal(turboStubbedResponse); | ||
expect((turboSpy.getFiatRates as sinon.SinonStub).calledOnce).to.be | ||
.true; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters