test: cover the export calendar-id plumbing
The fake now records the calendarIds it receives; two repository tests assert exportEvents forwards a chosen subset and defaults to null (all eligible calendars), closing the coverage gap for the per-calendar export selector. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -536,6 +536,30 @@ class CalendarRepositoryImplTest {
|
|||||||
assertThat(fake.importedEvents.map { it.second }).containsExactly(3L, 3L)
|
assertThat(fake.importedEvents.map { it.second }).containsExactly(3L, 3L)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `exportEvents forwards the chosen calendar-id subset to the data source`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
|
val fake = FakeCalendarDataSource()
|
||||||
|
val repo = CalendarRepositoryImpl(fake, newPrefs(tempDir), newSettings(tempDir), Dispatchers.Unconfined)
|
||||||
|
|
||||||
|
repo.exportEvents(calendarIds = setOf(1L, 4L))
|
||||||
|
|
||||||
|
assertThat(fake.lastExportableEventsCalendarIds).containsExactly(1L, 4L)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `exportEvents defaults to null so every eligible calendar is exported`(
|
||||||
|
@TempDir tempDir: Path,
|
||||||
|
) = runTest {
|
||||||
|
val fake = FakeCalendarDataSource()
|
||||||
|
val repo = CalendarRepositoryImpl(fake, newPrefs(tempDir), newSettings(tempDir), Dispatchers.Unconfined)
|
||||||
|
|
||||||
|
repo.exportEvents()
|
||||||
|
|
||||||
|
assertThat(fake.lastExportableEventsCalendarIds).isNull()
|
||||||
|
}
|
||||||
|
|
||||||
private fun parsedEvent(uid: String?) = de.jeanlucmakiola.calendula.domain.ics.ParsedIcsEvent(
|
private fun parsedEvent(uid: String?) = de.jeanlucmakiola.calendula.domain.ics.ParsedIcsEvent(
|
||||||
uid = uid,
|
uid = uid,
|
||||||
summary = "E",
|
summary = "E",
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ internal class FakeCalendarDataSource : CalendarDataSource {
|
|||||||
var eventDetailResult: (Long) -> EventDetail? = { null }
|
var eventDetailResult: (Long) -> EventDetail? = { null }
|
||||||
var eventColorPaletteResult: (Long) -> List<EventColorOption> = { emptyList() }
|
var eventColorPaletteResult: (Long) -> List<EventColorOption> = { emptyList() }
|
||||||
var exportableEventsResult: List<IcsEvent> = emptyList()
|
var exportableEventsResult: List<IcsEvent> = emptyList()
|
||||||
|
/** The [calendarIds] the last [exportableEvents] call received (null = all). */
|
||||||
|
var lastExportableEventsCalendarIds: Set<Long>? = null
|
||||||
/** UIDs the target calendar already holds, for import dedup. */
|
/** UIDs the target calendar already holds, for import dedup. */
|
||||||
var existingUidsResult: Set<String> = emptySet()
|
var existingUidsResult: Set<String> = emptySet()
|
||||||
/** Set to make the next write call throw. */
|
/** Set to make the next write call throw. */
|
||||||
@@ -59,7 +61,10 @@ internal class FakeCalendarDataSource : CalendarDataSource {
|
|||||||
override fun eventDetail(eventId: Long): EventDetail? = eventDetailResult(eventId)
|
override fun eventDetail(eventId: Long): EventDetail? = eventDetailResult(eventId)
|
||||||
override fun eventColorPalette(calendarId: Long): List<EventColorOption> =
|
override fun eventColorPalette(calendarId: Long): List<EventColorOption> =
|
||||||
eventColorPaletteResult(calendarId)
|
eventColorPaletteResult(calendarId)
|
||||||
override fun exportableEvents(calendarIds: Set<Long>?): List<IcsEvent> = exportableEventsResult
|
override fun exportableEvents(calendarIds: Set<Long>?): List<IcsEvent> {
|
||||||
|
lastExportableEventsCalendarIds = calendarIds
|
||||||
|
return exportableEventsResult
|
||||||
|
}
|
||||||
|
|
||||||
override fun existingUids(calendarId: Long): Set<String> = existingUidsResult
|
override fun existingUids(calendarId: Long): Set<String> = existingUidsResult
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user