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 452669c
Showing 1 changed file with 13 additions and 9 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 Down

0 comments on commit 452669c

Please sign in to comment.