Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
implement TestTimeConverter and fix ExportCsvUseCasePropertyTest
Browse files Browse the repository at this point in the history
  • Loading branch information
akashs056 committed Aug 31, 2024
1 parent 1d87add commit 6f08194
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.ivy.base.time.impl

import com.ivy.base.time.TimeConverter
import java.time.Instant
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZoneId

class TestTimeConverter : TimeConverter {
private val utcZoneId = ZoneId.of("UTC")

override fun Instant.toLocalDateTime(): LocalDateTime {
return this.atZone(utcZoneId).toLocalDateTime()
}

override fun Instant.toLocalDate(): LocalDate {
return this.atZone(utcZoneId).toLocalDate()
}

override fun LocalDateTime.toUTC(): Instant {
return this.atZone(utcZoneId).toInstant()
}

fun LocalDateTime.toInstant(): Instant {
return this.atZone(utcZoneId).toInstant()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ExportCsvUseCase @Inject constructor(
categoriesMap: Map<CategoryId, Category>,
): String = csvRow {
// Date
csvAppend(date?.csvFormat())
csvAppend(date?.csvFormat(timeConverter))
// Title
csvAppend(title?.value)
// Category
Expand All @@ -101,7 +101,7 @@ class ExportCsvUseCase @Inject constructor(
// Description
csvAppend(description?.value)
// Due Date
csvAppend(dueData?.csvFormat())
csvAppend(dueData?.csvFormat(timeConverter))
// ID
csvAppend(id.value.toString())
}
Expand Down Expand Up @@ -188,7 +188,7 @@ class ExportCsvUseCase @Inject constructor(
id = id
)

private fun Instant.csvFormat(): String {
private fun Instant.csvFormat(timeConverter: TimeConverter): String {
return with(timeConverter) {
this@csvFormat.toLocalDateTime()
}.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ivy.domain.usecase.csv

import arrow.core.Some
import com.ivy.base.TestDispatchersProvider
import com.ivy.base.time.impl.TestTimeConverter
import com.ivy.data.file.FileSystem
import com.ivy.data.model.Transaction
import com.ivy.data.model.getFromAccount
Expand Down Expand Up @@ -30,6 +31,7 @@ class ExportCsvUseCasePropertyTest {
private val categoryRepository = mockk<CategoryRepository>(relaxed = true)
private val transactionRepository = mockk<TransactionRepository>()
private val fileSystem = mockk<FileSystem>()
private val timeConverter = TestTimeConverter()

private lateinit var useCase: ExportCsvUseCase

Expand All @@ -41,6 +43,7 @@ class ExportCsvUseCasePropertyTest {
transactionRepository = transactionRepository,
dispatchers = TestDispatchersProvider,
fileSystem = fileSystem,
timeConverter = timeConverter,
)
}

Expand Down

0 comments on commit 6f08194

Please sign in to comment.