Updated on 2026-08-14
This commit is contained in:
parent
5b1663edc7
commit
03bef8f61f
2 changed files with 41 additions and 46 deletions
|
|
@ -440,5 +440,42 @@ internal class DefaultQuotesFetcherTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `fetch successfully if not all quotes are fetched`() = runTest {
|
||||
// Arrange
|
||||
val apiQuote = MockQuoteResponseFactory.createSinglePrice(BigDecimal.ONE)
|
||||
val apiResponse = ApiResponse.Success(
|
||||
data = QuotesResponse(quotes = mapOf("ethereum" to apiQuote)),
|
||||
)
|
||||
|
||||
coEvery {
|
||||
tangemTechApi.getQuotes(currencyId = "usd", coinIds = "ethereum,bitcoin", fields = "price")
|
||||
} returns apiResponse
|
||||
|
||||
// Act
|
||||
val actual = fetcher.fetch(
|
||||
fiatCurrencyId = "usd",
|
||||
currenciesIds = setOf("ethereum", "bitcoin"),
|
||||
fields = setOf(Field.PRICE),
|
||||
)
|
||||
|
||||
// Assert
|
||||
val expected = QuotesResponse(
|
||||
quotes = mapOf(
|
||||
"ethereum" to apiQuote,
|
||||
"bitcoin" to QuotesResponse.Quote.EMPTY,
|
||||
),
|
||||
).right()
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
|
||||
coVerify(exactly = 1) {
|
||||
tangemTechApi.getQuotes(
|
||||
currencyId = "usd",
|
||||
coinIds = "ethereum,bitcoin",
|
||||
fields = "price",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Iterable<QuoteMetadata>?.toResponseQuotes() = this!!.associate { it.cryptoCurrencyId to it.value }
|
||||
}
|
||||
|
|
@ -161,7 +161,7 @@ internal class DefaultMultiQuoteStatusFetcherTest {
|
|||
val params = MultiQuoteStatusFetcher.Params(currenciesIds = currenciesIds, appCurrencyId = null)
|
||||
|
||||
val currenciesIds = setOf("BTC", "ETH")
|
||||
val error = QuotesFetcher.Error.ApiOperationError(ApiResponseError.NetworkException)
|
||||
val error = QuotesFetcher.Error.ApiOperationError(ApiResponseError.NetworkException())
|
||||
|
||||
coEvery { appCurrencyResponseStore.getSyncOrNull() } returns usdAppCurrency
|
||||
|
||||
|
|
@ -173,7 +173,9 @@ internal class DefaultMultiQuoteStatusFetcherTest {
|
|||
val actual = fetcher(params)
|
||||
|
||||
// Assert
|
||||
val expected = IllegalStateException("Cause: ApiOperationError(apiError=NetworkException)").left()
|
||||
val expected = IllegalStateException(
|
||||
"Cause: ApiOperationError(apiError=com.tangem.datasource.api.common.response.ApiResponseError\$NetworkException)",
|
||||
).left()
|
||||
assertEither(actual, expected)
|
||||
|
||||
coVerifyOrder {
|
||||
|
|
@ -215,50 +217,6 @@ internal class DefaultMultiQuoteStatusFetcherTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `fetch successfully if not all quotes are fetched`() = runTest {
|
||||
// Arrange
|
||||
val params = MultiQuoteStatusFetcher.Params(currenciesIds = currenciesIds, appCurrencyId = null)
|
||||
|
||||
coEvery { appCurrencyResponseStore.getSyncOrNull() } returns usdAppCurrency
|
||||
|
||||
val currenciesIds = setOf("BTC", "ETH")
|
||||
val response = QuotesResponse(
|
||||
quotes = mapOf(
|
||||
"BTC" to MockQuoteResponseFactory.createSinglePrice(value = BigDecimal.ONE),
|
||||
),
|
||||
)
|
||||
|
||||
coEvery {
|
||||
quotesFetcher.fetch(fiatCurrencyId = "usd", currenciesIds = currenciesIds, fields = fields)
|
||||
} returns response.right()
|
||||
|
||||
// Act
|
||||
val actual = fetcher(params)
|
||||
|
||||
// Assert
|
||||
val expected = Unit.right()
|
||||
Truth.assertThat(actual).isEqualTo(expected)
|
||||
|
||||
val storedQuotes = QuotesResponse(
|
||||
quotes = mapOf(
|
||||
"BTC" to MockQuoteResponseFactory.createSinglePrice(value = BigDecimal.ONE),
|
||||
"ETH" to QuotesResponse.Quote.EMPTY,
|
||||
),
|
||||
)
|
||||
|
||||
coVerifyOrder {
|
||||
quotesStore.setSourceAsCache(currenciesIds = params.currenciesIds)
|
||||
appCurrencyResponseStore.getSyncOrNull()
|
||||
quotesFetcher.fetch(fiatCurrencyId = "usd", currenciesIds = currenciesIds, fields = fields)
|
||||
quotesStore.store(values = storedQuotes.quotes)
|
||||
}
|
||||
|
||||
coVerify(inverse = true) {
|
||||
quotesStore.setSourceAsOnlyCache(currenciesIds = any())
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
||||
val currenciesIds = setOf(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue