|
| 1 | +package chat.rocket.reactnative.voip |
| 2 | + |
| 3 | +import org.junit.Assert.assertEquals |
| 4 | +import org.junit.Assert.assertFalse |
| 5 | +import org.junit.Assert.assertNull |
| 6 | +import org.junit.Assert.assertTrue |
| 7 | +import org.junit.Test |
| 8 | + |
| 9 | +class VoipPerCallDdpRegistryTest { |
| 10 | + |
| 11 | + private fun registry(): Pair<MutableList<String>, VoipPerCallDdpRegistry<String>> { |
| 12 | + val released = mutableListOf<String>() |
| 13 | + return released to VoipPerCallDdpRegistry { released.add(it) } |
| 14 | + } |
| 15 | + |
| 16 | + @Test |
| 17 | + fun `stopClient removes only the named callId`() { |
| 18 | + val (released, reg) = registry() |
| 19 | + reg.putClient("callA", "clientA") |
| 20 | + reg.putClient("callB", "clientB") |
| 21 | + reg.stopClient("callA") |
| 22 | + assertEquals(listOf("clientA"), released) |
| 23 | + assertEquals(setOf("callB"), reg.clientIds()) |
| 24 | + assertEquals("clientB", reg.clientFor("callB")) |
| 25 | + assertNull(reg.clientFor("callA")) |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + fun `stopAllClients disconnects every entry`() { |
| 30 | + val (released, reg) = registry() |
| 31 | + reg.putClient("callA", "clientA") |
| 32 | + reg.putClient("callB", "clientB") |
| 33 | + reg.stopAllClients() |
| 34 | + assertEquals(2, released.size) |
| 35 | + assertTrue(released.containsAll(listOf("clientA", "clientB"))) |
| 36 | + assertEquals(0, reg.clientCount()) |
| 37 | + assertTrue(reg.clientIds().isEmpty()) |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + fun `starting a second listener for another callId does not release the first`() { |
| 42 | + val (released, reg) = registry() |
| 43 | + reg.putClient("callA", "clientA") |
| 44 | + reg.putClient("callB", "clientB") |
| 45 | + assertTrue(released.isEmpty()) |
| 46 | + assertEquals(setOf("callA", "callB"), reg.clientIds()) |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + fun `putClient for the same callId releases the previous client`() { |
| 51 | + val (released, reg) = registry() |
| 52 | + reg.putClient("callA", "first") |
| 53 | + reg.putClient("callA", "second") |
| 54 | + assertEquals(listOf("first"), released) |
| 55 | + assertEquals("second", reg.clientFor("callA")) |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + fun `loggedIn state is per callId`() { |
| 60 | + val (_, reg) = registry() |
| 61 | + reg.putClient("callA", "a") |
| 62 | + reg.putClient("callB", "b") |
| 63 | + assertFalse(reg.isLoggedIn("callA")) |
| 64 | + reg.markLoggedIn("callA") |
| 65 | + assertTrue(reg.isLoggedIn("callA")) |
| 66 | + assertFalse(reg.isLoggedIn("callB")) |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + fun `stopClient clears loggedIn for that callId`() { |
| 71 | + val (_, reg) = registry() |
| 72 | + reg.putClient("callA", "a") |
| 73 | + reg.markLoggedIn("callA") |
| 74 | + reg.stopClient("callA") |
| 75 | + assertFalse(reg.isLoggedIn("callA")) |
| 76 | + } |
| 77 | +} |
0 commit comments