Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal class SessionEventRepositoryImpl @Inject constructor(
closeAllSessions(EventScopeEndCause.NEW_SESSION)
return eventRepository.createEventScope(EventScopeType.SESSION).also { sessionScope ->
sessionDataCache.eventScope = sessionScope
sessionDataCache.eventCache.clear()
}
}

Expand Down Expand Up @@ -81,9 +82,9 @@ internal class SessionEventRepositoryImpl @Inject constructor(
?.also { session -> loadEventsIntoCache(session.id) }

private suspend fun loadEventsIntoCache(sessionId: String) {
eventRepository.getEventsFromScope(sessionId).forEach {
sessionDataCache.eventCache[it.id] = it
}
sessionDataCache.eventCache.clear()
eventRepository.getEventsFromScope(sessionId)
.forEach { sessionDataCache.eventCache[it.id] = it }
}

override suspend fun closeCurrentSession(reason: EventScopeEndCause?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ internal class SessionEventRepositoryImplTest {
assertThat(sessionDataCache.eventScope).isNotNull()
}

@Test
fun `when create session is called, then the event cache is cleared`() = runTest {
coEvery { eventRepository.createEventScope(any()) } returns mockk()
sessionDataCache.eventCache["test"] = mockk()

sessionEventRepository.createSession()

coVerify { eventRepository.createEventScope(EventScopeType.SESSION) }
assertThat(sessionDataCache.eventCache).isEmpty()
}

@Test
fun `closes existing sessions when creating new session`() = runTest {
coEvery { eventRepository.createEventScope(any()) } returns createSessionScope("mockId")
Expand Down Expand Up @@ -112,10 +123,12 @@ internal class SessionEventRepositoryImplTest {
@Test
fun `return current scope from db if no cache`() = runTest {
coEvery { eventRepository.getOpenEventScopes(any()) } returns listOf(createSessionScope("mockId"))
sessionDataCache.eventCache["test"] = mockk()

val loadedSession = sessionEventRepository.getCurrentSessionScope()

assertThat(loadedSession.id).isEqualTo("mockId")
assertThat(sessionDataCache.eventCache).isEmpty()
}

@Test
Expand Down