Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
patxibocos committed Jul 7, 2023
1 parent fe37bc4 commit 324163c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal fun getAppArgs(args: Array<String>): AppArgs {
ArgType.Choice<ItemType>(),
shortName = "it",
description = "Item types to include",
).multiple().default(ItemType.values().toList())
).multiple().default(ItemType.entries)
val maxChunkSize by parser.option(
ArgType.Int,
shortName = "mcs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import java.time.format.DateTimeFormatter
import kotlin.time.Duration

sealed interface ExportEvent {
object ExportStarted : ExportEvent
data object ExportStarted : ExportEvent
data class ItemsCollected(val photos: Int, val videos: Int) : ExportEvent
data class ItemDownloaded(val item: Item) : ExportEvent
data class ItemUploaded(val item: Item) : ExportEvent
object DownloadFailed : ExportEvent
object UploadFailed : ExportEvent
object ExportCompleted : ExportEvent
data object DownloadFailed : ExportEvent
data object UploadFailed : ExportEvent
data object ExportCompleted : ExportEvent
}

class ExportItems(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import io.mockk.coVerifyOrder
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flow
Expand All @@ -18,7 +17,6 @@ import java.time.Instant
import kotlin.test.Test
import kotlin.time.Duration

@OptIn(ExperimentalCoroutinesApi::class)
@ExtendWith(MockKExtension::class)
class ExportItemsTest {

Expand All @@ -30,14 +28,14 @@ class ExportItemsTest {

@Test
fun `when no items on photos repository then nothing is uploaded`() = runTest {
every { googlePhotosRepository.download(ItemType.values().toList(), null, any()) } returns emptyFlow()
every { googlePhotosRepository.download(ItemType.entries, null, any()) } returns emptyFlow()
coEvery { exporter.get(any()) } returns null
val exportItems = ExportItems(googlePhotosRepository, exporter, false)

exportItems(
offsetId = null,
datePathPattern = "yyyy/MM/dd",
itemTypes = ItemType.values().toList(),
itemTypes = ItemType.entries,
timeout = Duration.INFINITE,
).collect()

Expand All @@ -47,7 +45,7 @@ class ExportItemsTest {
@Test
fun `when many items on photos repository then every item is uploaded in order`() =
runTest {
every { googlePhotosRepository.download(ItemType.values().toList(), null, any()) } returns flowOf(
every { googlePhotosRepository.download(ItemType.entries, null, any()) } returns flowOf(
Item(byteArrayOf(), "id1", "item1.jpg", Instant.EPOCH),
Item(byteArrayOf(), "id2", "item2.jpg", Instant.EPOCH),
)
Expand All @@ -58,7 +56,7 @@ class ExportItemsTest {
exportItems(
offsetId = null,
datePathPattern = "yyyy/MM/dd",
itemTypes = ItemType.values().toList(),
itemTypes = ItemType.entries,
timeout = Duration.INFINITE,
).collect()

Expand All @@ -70,7 +68,7 @@ class ExportItemsTest {

@Test
fun `when emitting an item fails then collection stops`() = runTest {
every { googlePhotosRepository.download(ItemType.values().toList(), null, any()) } returns flow {
every { googlePhotosRepository.download(ItemType.entries, null, any()) } returns flow {
emit(Item(byteArrayOf(), "id1", "item1.jpg", Instant.EPOCH))
throw Exception()
}
Expand All @@ -81,7 +79,7 @@ class ExportItemsTest {
exportItems(
offsetId = null,
datePathPattern = "yyyy/MM/dd",
itemTypes = ItemType.values().toList(),
itemTypes = ItemType.entries,
timeout = Duration.INFINITE,
).collect()

Expand All @@ -92,14 +90,14 @@ class ExportItemsTest {

@Test
fun `when passing an explicit offset ID then it is used as offset`() = runTest {
every { googlePhotosRepository.download(ItemType.values().toList(), "last-item-id", any()) } returns emptyFlow()
every { googlePhotosRepository.download(ItemType.entries, "last-item-id", any()) } returns emptyFlow()
val exportItems =
ExportItems(googlePhotosRepository, exporter, false)

exportItems(
offsetId = "last-item-id",
datePathPattern = "yyyy/MM/dd",
itemTypes = ItemType.values().toList(),
itemTypes = ItemType.entries,
timeout = Duration.INFINITE,
).collect()
}
Expand Down

0 comments on commit 324163c

Please sign in to comment.