Skip to content

Commit 3b303d6

Browse files
committed
Merge branch 'fix-ci-pipeline' into main
2 parents 99f3dca + 3703572 commit 3b303d6

File tree

13 files changed

+403
-114
lines changed

13 files changed

+403
-114
lines changed

app/src/main/java/dev/shorthouse/coinwatch/common/Mapper.kt

-5
This file was deleted.

app/src/main/java/dev/shorthouse/coinwatch/data/datastore/UserPreferences.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import kotlinx.serialization.Serializable
44

55
@Serializable
66
data class UserPreferences(
7-
val currency: Currency = Currency.USD,
8-
val coinSort: CoinSort = CoinSort.MarketCap
7+
val coinSort: CoinSort = CoinSort.MarketCap,
8+
val currency: Currency = Currency.USD
99
)
1010

1111
enum class Currency(val symbol: String) {

app/src/main/java/dev/shorthouse/coinwatch/data/mapper/CoinChartMapper.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import javax.inject.Inject
1111
import kotlinx.collections.immutable.toPersistentList
1212

1313
class CoinChartMapper @Inject constructor() {
14-
fun mapApiModelToModel(from: CoinChartApiModel, currency: Currency): CoinChart {
15-
val validPrices = from.coinChartData?.pastPrices
14+
fun mapApiModelToModel(apiModel: CoinChartApiModel, currency: Currency): CoinChart {
15+
val validPrices = apiModel.coinChartData?.pastPrices
1616
.orEmpty()
1717
.mapNotNull { pastPrice ->
1818
pastPrice?.amount.toSanitisedBigDecimalOrNull()
@@ -34,7 +34,7 @@ class CoinChartMapper @Inject constructor() {
3434
prices = validPrices.toPersistentList(),
3535
minPrice = Price(minPrice, currency = currency),
3636
maxPrice = Price(maxPrice, currency = currency),
37-
periodPriceChangePercentage = Percentage(from.coinChartData?.priceChangePercentage)
37+
periodPriceChangePercentage = Percentage(apiModel.coinChartData?.priceChangePercentage)
3838
)
3939
}
4040
}

app/src/main/java/dev/shorthouse/coinwatch/data/mapper/CoinDetailsMapper.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class CoinDetailsMapper @Inject constructor() {
2121
}
2222
}
2323

24-
fun mapApiModelToModel(from: CoinDetailsApiModel, currency: Currency): CoinDetails {
25-
val coinDetails = from.coinDetailsDataHolder?.coinDetailsData
24+
fun mapApiModelToModel(apiModel: CoinDetailsApiModel, currency: Currency): CoinDetails {
25+
val coinDetails = apiModel.coinDetailsDataHolder?.coinDetailsData
2626

2727
return CoinDetails(
2828
id = coinDetails?.id.orEmpty(),

app/src/main/java/dev/shorthouse/coinwatch/data/mapper/CoinMapper.kt

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.shorthouse.coinwatch.data.mapper
22

33
import dev.shorthouse.coinwatch.data.datastore.Currency
4+
import dev.shorthouse.coinwatch.data.source.local.model.CachedCoin
45
import dev.shorthouse.coinwatch.data.source.remote.model.CoinsApiModel
56
import dev.shorthouse.coinwatch.model.Coin
67
import dev.shorthouse.coinwatch.model.Percentage
@@ -10,8 +11,8 @@ import javax.inject.Inject
1011
import kotlinx.collections.immutable.toPersistentList
1112

1213
class CoinMapper @Inject constructor() {
13-
fun mapApiModelToModel(from: CoinsApiModel, currency: Currency): List<Coin> {
14-
val validCoins = from.coinsData?.coins
14+
fun mapApiModelToModel(apiModel: CoinsApiModel, currency: Currency): List<Coin> {
15+
val validCoins = apiModel.coinsData?.coins
1516
.orEmpty()
1617
.filterNotNull()
1718
.filter { it.id != null }
@@ -32,4 +33,16 @@ class CoinMapper @Inject constructor() {
3233
)
3334
}
3435
}
36+
37+
fun mapCachedCoinToModel(cachedCoin: CachedCoin): Coin {
38+
return Coin(
39+
id = cachedCoin.id,
40+
name = cachedCoin.name,
41+
symbol = cachedCoin.symbol,
42+
imageUrl = cachedCoin.imageUrl,
43+
currentPrice = cachedCoin.currentPrice,
44+
priceChangePercentage24h = cachedCoin.priceChangePercentage24h,
45+
prices24h = cachedCoin.prices24h
46+
)
47+
}
3548
}

app/src/test/java/dev/shorthouse/coinwatch/data/mapper/CoinChartMapperTest.kt

+39-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.shorthouse.coinwatch.data.mapper
22

33
import com.google.common.truth.Truth.assertThat
4+
import dev.shorthouse.coinwatch.data.datastore.Currency
45
import dev.shorthouse.coinwatch.data.source.remote.model.CoinChartApiModel
56
import dev.shorthouse.coinwatch.data.source.remote.model.CoinChartData
67
import dev.shorthouse.coinwatch.data.source.remote.model.PastPrice
@@ -16,6 +17,8 @@ class CoinChartMapperTest {
1617
// Class under test
1718
private val coinChartMapper = CoinChartMapper()
1819

20+
private val currency = Currency.USD
21+
1922
@Test
2023
fun `When coin chart data is null should return default values`() {
2124
// Arrange
@@ -31,7 +34,10 @@ class CoinChartMapperTest {
3134
)
3235

3336
// Act
34-
val coinChart = coinChartMapper.mapApiModelToModel(apiModel)
37+
val coinChart = coinChartMapper.mapApiModelToModel(
38+
apiModel = apiModel,
39+
currency = currency
40+
)
3541

3642
// Assert
3743
assertThat(coinChart).isEqualTo(expectedCoinChart)
@@ -55,7 +61,10 @@ class CoinChartMapperTest {
5561
)
5662

5763
// Act
58-
val coinChart = coinChartMapper.mapApiModelToModel(apiModel)
64+
val coinChart = coinChartMapper.mapApiModelToModel(
65+
apiModel = apiModel,
66+
currency = currency
67+
)
5968

6069
// Assert
6170
assertThat(coinChart).isEqualTo(expectedCoinChart)
@@ -79,7 +88,10 @@ class CoinChartMapperTest {
7988
)
8089

8190
// Act
82-
val coinChart = coinChartMapper.mapApiModelToModel(apiModel)
91+
val coinChart = coinChartMapper.mapApiModelToModel(
92+
apiModel = apiModel,
93+
currency = currency
94+
)
8395

8496
// Assert
8597
assertThat(coinChart).isEqualTo(expectedCoinChart)
@@ -103,7 +115,10 @@ class CoinChartMapperTest {
103115
)
104116

105117
// Act
106-
val coinChart = coinChartMapper.mapApiModelToModel(apiModel)
118+
val coinChart = coinChartMapper.mapApiModelToModel(
119+
apiModel = apiModel,
120+
currency = currency
121+
)
107122

108123
// Assert
109124
assertThat(coinChart).isEqualTo(expectedCoinChart)
@@ -134,7 +149,10 @@ class CoinChartMapperTest {
134149
)
135150

136151
// Act
137-
val coinChart = coinChartMapper.mapApiModelToModel(apiModel)
152+
val coinChart = coinChartMapper.mapApiModelToModel(
153+
apiModel = apiModel,
154+
currency = currency
155+
)
138156

139157
// Assert
140158
assertThat(coinChart).isEqualTo(expectedCoinChart)
@@ -164,7 +182,10 @@ class CoinChartMapperTest {
164182
)
165183

166184
// Act
167-
val coinChart = coinChartMapper.mapApiModelToModel(apiModel)
185+
val coinChart = coinChartMapper.mapApiModelToModel(
186+
apiModel = apiModel,
187+
currency = currency
188+
)
168189

169190
// Assert
170191
assertThat(coinChart).isEqualTo(expectedCoinChart)
@@ -197,7 +218,10 @@ class CoinChartMapperTest {
197218
)
198219

199220
// Act
200-
val coinChart = coinChartMapper.mapApiModelToModel(apiModel)
221+
val coinChart = coinChartMapper.mapApiModelToModel(
222+
apiModel = apiModel,
223+
currency = currency
224+
)
201225

202226
// Assert
203227
assertThat(coinChart).isEqualTo(expectedCoinChart)
@@ -233,7 +257,10 @@ class CoinChartMapperTest {
233257
)
234258

235259
// Act
236-
val coinChart = coinChartMapper.mapApiModelToModel(apiModel)
260+
val coinChart = coinChartMapper.mapApiModelToModel(
261+
apiModel = apiModel,
262+
currency = currency
263+
)
237264

238265
// Assert
239266
assertThat(coinChart).isEqualTo(expectedCoinChart)
@@ -269,7 +296,10 @@ class CoinChartMapperTest {
269296
)
270297

271298
// Act
272-
val coinChart = coinChartMapper.mapApiModelToModel(apiModel)
299+
val coinChart = coinChartMapper.mapApiModelToModel(
300+
apiModel = apiModel,
301+
currency = currency
302+
)
273303

274304
// Assert
275305
assertThat(coinChart).isEqualTo(expectedCoinChart)

app/src/test/java/dev/shorthouse/coinwatch/data/mapper/CoinDetailsMapperTest.kt

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.shorthouse.coinwatch.data.mapper
22

33
import com.google.common.truth.Truth.assertThat
4+
import dev.shorthouse.coinwatch.data.datastore.Currency
45
import dev.shorthouse.coinwatch.data.source.remote.model.AllTimeHigh
56
import dev.shorthouse.coinwatch.data.source.remote.model.CoinDetailsApiModel
67
import dev.shorthouse.coinwatch.data.source.remote.model.CoinDetailsData
@@ -15,6 +16,8 @@ class CoinDetailsMapperTest {
1516
// Class under test
1617
private val coinDetailsMapper = CoinDetailsMapper()
1718

19+
private val currency = Currency.USD
20+
1821
@Test
1922
fun `When coin details data holder is null should return default values`() {
2023
// Arrange
@@ -38,7 +41,10 @@ class CoinDetailsMapperTest {
3841
)
3942

4043
// Act
41-
val coinDetails = coinDetailsMapper.mapApiModelToModel(coinDetailsApiModel)
44+
val coinDetails = coinDetailsMapper.mapApiModelToModel(
45+
apiModel = coinDetailsApiModel,
46+
currency = currency
47+
)
4248

4349
// Assert
4450
assertThat(coinDetails).isEqualTo(expectedCoinDetails)
@@ -69,7 +75,10 @@ class CoinDetailsMapperTest {
6975
)
7076

7177
// Act
72-
val coinDetails = coinDetailsMapper.mapApiModelToModel(coinDetailsApiModel)
78+
val coinDetails = coinDetailsMapper.mapApiModelToModel(
79+
apiModel = coinDetailsApiModel,
80+
currency = currency
81+
)
7382

7483
// Assert
7584
assertThat(coinDetails).isEqualTo(expectedCoinDetails)
@@ -112,7 +121,10 @@ class CoinDetailsMapperTest {
112121
)
113122

114123
// Act
115-
val coinDetails = coinDetailsMapper.mapApiModelToModel(coinDetailsApiModel)
124+
val coinDetails = coinDetailsMapper.mapApiModelToModel(
125+
apiModel = coinDetailsApiModel,
126+
currency = currency
127+
)
116128

117129
// Assert
118130
assertThat(coinDetails).isEqualTo(expectedCoinDetails)
@@ -160,7 +172,10 @@ class CoinDetailsMapperTest {
160172
)
161173

162174
// Act
163-
val coinDetails = coinDetailsMapper.mapApiModelToModel(coinDetailsApiModel)
175+
val coinDetails = coinDetailsMapper.mapApiModelToModel(
176+
apiModel = coinDetailsApiModel,
177+
currency = currency
178+
)
164179

165180
// Assert
166181
assertThat(coinDetails).isEqualTo(expectedCoinDetails)
@@ -208,7 +223,10 @@ class CoinDetailsMapperTest {
208223
)
209224

210225
// Act
211-
val coinDetails = coinDetailsMapper.mapApiModelToModel(coinDetailsApiModel)
226+
val coinDetails = coinDetailsMapper.mapApiModelToModel(
227+
apiModel = coinDetailsApiModel,
228+
currency = currency
229+
)
212230

213231
// Assert
214232
assertThat(coinDetails).isEqualTo(expectedCoinDetails)
@@ -256,7 +274,10 @@ class CoinDetailsMapperTest {
256274
)
257275

258276
// Act
259-
val coinDetails = coinDetailsMapper.mapApiModelToModel(coinDetailsApiModel)
277+
val coinDetails = coinDetailsMapper.mapApiModelToModel(
278+
coinDetailsApiModel,
279+
currency = currency
280+
)
260281

261282
// Assert
262283
assertThat(coinDetails).isEqualTo(expectedCoinDetails)

0 commit comments

Comments
 (0)