Skip to content

Commit

Permalink
Refactored room attach tests with proper naming convention,
Browse files Browse the repository at this point in the history
replaced magical error codes with reference to ErrorCode enum constant
  • Loading branch information
sacOO7 committed Nov 12, 2024
1 parent 097e82c commit f4883bc
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ class RoomLifecycleManagerTest {
)

@Test
fun `(CHA-RL1a) Attach success when channel in already in attached state`() = runTest {
fun `(CHA-RL1a) Attach success when room is already in attached state`() = runTest {
val status = spyk<DefaultStatus>().apply {
setStatus(RoomLifecycle.Attached)
}
val roomLifecycle = spyk(RoomLifecycleManager(roomScope, status, createRoomFeatureMocks()))
val result = kotlin.runCatching { roomLifecycle.attach() }
Assert.assertTrue(result.isSuccess)
assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }
}

@Test
fun `(CHA-RL1b) Attach throws exception when channel in releasing state`() = runTest {
fun `(CHA-RL1b) Attach throws exception when room in releasing state`() = runTest {
val status = spyk<DefaultStatus>().apply {
setStatus(RoomLifecycle.Releasing)
}
Expand All @@ -55,12 +56,13 @@ class RoomLifecycleManagerTest {
}
}
Assert.assertEquals("unable to attach room; room is releasing", exception.errorInfo.message)
Assert.assertEquals(102_102, exception.errorInfo.code)
Assert.assertEquals(500, exception.errorInfo.statusCode)
Assert.assertEquals(ErrorCodes.RoomIsReleasing.errorCode, exception.errorInfo.code)
Assert.assertEquals(HttpStatusCodes.InternalServerError, exception.errorInfo.statusCode)
assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }
}

@Test
fun `(CHA-RL1c) Attach throws exception when channel in released state`() = runTest {
fun `(CHA-RL1c) Attach throws exception when room in released state`() = runTest {
val status = spyk<DefaultStatus>().apply {
setStatus(RoomLifecycle.Released)
}
Expand All @@ -71,8 +73,9 @@ class RoomLifecycleManagerTest {
}
}
Assert.assertEquals("unable to attach room; room is released", exception.errorInfo.message)
Assert.assertEquals(102_103, exception.errorInfo.code)
Assert.assertEquals(500, exception.errorInfo.statusCode)
Assert.assertEquals(ErrorCodes.RoomIsReleased.errorCode, exception.errorInfo.code)
Assert.assertEquals(HttpStatusCodes.InternalServerError, exception.errorInfo.statusCode)
assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }
}

@Test
Expand Down Expand Up @@ -115,8 +118,9 @@ class RoomLifecycleManagerTest {
val exception = result.exceptionOrNull() as AblyException

Assert.assertEquals("unable to attach room; room is released", exception.errorInfo.message)
Assert.assertEquals(102_103, exception.errorInfo.code)
Assert.assertEquals(500, exception.errorInfo.statusCode)
Assert.assertEquals(ErrorCodes.RoomIsReleased.errorCode, exception.errorInfo.code)
Assert.assertEquals(HttpStatusCodes.InternalServerError, exception.errorInfo.statusCode)
assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }

coVerify { roomLifecycle.release() }
}
Expand All @@ -130,6 +134,7 @@ class RoomLifecycleManagerTest {
}
val roomLifecycle = spyk(RoomLifecycleManager(roomScope, status, emptyList()))
roomLifecycle.attach()

Assert.assertEquals(RoomLifecycle.Attaching, roomStatusChanges[0].current)
Assert.assertEquals(RoomLifecycle.Attached, roomStatusChanges[1].current)
assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }
Expand All @@ -149,7 +154,7 @@ class RoomLifecycleManagerTest {
Assert.assertEquals(5, contributors.size)

val roomLifecycle = spyk(RoomLifecycleManager(roomScope, status, contributors))
roomLifecycle.attach()

val result = kotlin.runCatching { roomLifecycle.attach() }
Assert.assertTrue(result.isSuccess)

Expand Down Expand Up @@ -190,7 +195,6 @@ class RoomLifecycleManagerTest {
}
justRun { roomLifecycle invokeNoArgs "clearAllTransientDetachTimeouts" }

roomLifecycle.attach()
val result = kotlin.runCatching { roomLifecycle.attach() }

// CHA-RL1g1
Expand Down

0 comments on commit f4883bc

Please sign in to comment.