Skip to content

Commit

Permalink
tests: split adding new event tests
Browse files Browse the repository at this point in the history
in `InMemoryBuffer`
  • Loading branch information
wzieba committed Nov 9, 2023
1 parent 591a72d commit 86ac0eb
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ internal class InMemoryBufferTest {

@Test
fun `when adding a new event, then save it to local storage and run onEventAdded listener`() = runTest {
// given
val event = mapOf("test" to 123)
sut = InMemoryBuffer(backgroundScope, repository) { }

// when
sut.add(event)
advanceTimeBy(1.seconds)
runCurrent()
backgroundScope.cancel()

// then
assertThat(repository.getStoredQueue()).containsOnlyOnce(event)
}

@Test
fun `given an onEventAdded listener, when adding a new event, then run the onEventAdded listener`() = runTest {
// given
val event = mapOf("test" to 123)
var onEventAddedExecuted = false
Expand All @@ -33,8 +49,7 @@ internal class InMemoryBufferTest {
backgroundScope.cancel()

// then
assertThat(repository.getStoredQueue()).containsOnlyOnce(event)
assertThat(onEventAddedExecuted).isTrue()
assertThat(onEventAddedExecuted).isTrue
}

@Test
Expand Down

0 comments on commit 86ac0eb

Please sign in to comment.