From 03bef8f61f81f305f1dd4bdff94001f33fab2683 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 1 Oct 2025 13:59:11 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../common/quote/DefaultQuotesFetcherTest.kt | 37 ++++++++++++++ .../DefaultMultiQuoteStatusFetcherTest.kt | 50 ++----------------- 2 files changed, 41 insertions(+), 46 deletions(-) diff --git a/data/common/src/test/kotlin/com/tangem/data/common/quote/DefaultQuotesFetcherTest.kt b/data/common/src/test/kotlin/com/tangem/data/common/quote/DefaultQuotesFetcherTest.kt index b179f463e6..0569178c46 100644 --- a/data/common/src/test/kotlin/com/tangem/data/common/quote/DefaultQuotesFetcherTest.kt +++ b/data/common/src/test/kotlin/com/tangem/data/common/quote/DefaultQuotesFetcherTest.kt @@ -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?.toResponseQuotes() = this!!.associate { it.cryptoCurrencyId to it.value } } \ No newline at end of file diff --git a/data/quotes/src/test/java/com/tangem/data/quotes/multi/DefaultMultiQuoteStatusFetcherTest.kt b/data/quotes/src/test/java/com/tangem/data/quotes/multi/DefaultMultiQuoteStatusFetcherTest.kt index 16d16ee6b0..958da45528 100644 --- a/data/quotes/src/test/java/com/tangem/data/quotes/multi/DefaultMultiQuoteStatusFetcherTest.kt +++ b/data/quotes/src/test/java/com/tangem/data/quotes/multi/DefaultMultiQuoteStatusFetcherTest.kt @@ -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(