Commit 24860c1a authored by Marius Volkhart's avatar Marius Volkhart

Restore unit tests

parent 2d35ff14
...@@ -57,7 +57,7 @@ jobs: ...@@ -57,7 +57,7 @@ jobs:
command: ./gradlew lint command: ./gradlew lint
- run: - run:
name: Run Unit test name: Run Unit test
command: echo ./gradlew test # TODO: Fix unit test errors soon... command: ./gradlew test
- store_artifacts: - store_artifacts:
path: app/build/reports/ path: app/build/reports/
destination: reports destination: reports
......
...@@ -3,6 +3,7 @@ package chat.rocket.android ...@@ -3,6 +3,7 @@ package chat.rocket.android
import chat.rocket.android.server.infraestructure.MemoryMessagesRepository import chat.rocket.android.server.infraestructure.MemoryMessagesRepository
import chat.rocket.core.model.Message import chat.rocket.core.model.Message
import chat.rocket.core.model.MessageType import chat.rocket.core.model.MessageType
import kotlinx.coroutines.experimental.runBlocking
import org.hamcrest.CoreMatchers.notNullValue import org.hamcrest.CoreMatchers.notNullValue
import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.MatcherAssert.assertThat
import org.junit.Before import org.junit.Before
...@@ -30,7 +31,9 @@ class MemoryMessagesRepositoryTest { ...@@ -30,7 +31,9 @@ class MemoryMessagesRepositoryTest {
senderAlias = null, senderAlias = null,
type = MessageType.MessageRemoved(), type = MessageType.MessageRemoved(),
updatedAt = 1511443964815, updatedAt = 1511443964815,
urls = null urls = null,
pinned = false,
reactions = null
) )
val msg2 = Message( val msg2 = Message(
...@@ -50,86 +53,98 @@ class MemoryMessagesRepositoryTest { ...@@ -50,86 +53,98 @@ class MemoryMessagesRepositoryTest {
senderAlias = null, senderAlias = null,
type = MessageType.MessageRemoved(), type = MessageType.MessageRemoved(),
updatedAt = 1511443964818, updatedAt = 1511443964818,
urls = null urls = null,
pinned = false,
reactions = null
) )
@Before @Before
fun setup() { fun setup() {
repository.clear() runBlocking {
repository.clear()
}
} }
@Test @Test
fun `save() should save a single message`() { fun `save() should save a single message`() {
assertThat(repository.getAll().size, isEqualTo(0)) runBlocking {
repository.save(msg) assertThat(repository.getAll().size, isEqualTo(0))
val allMessages = repository.getAll() repository.save(msg)
assertThat(allMessages.size, isEqualTo(1)) val allMessages = repository.getAll()
allMessages[0].apply { assertThat(allMessages.size, isEqualTo(1))
assertThat(id, isEqualTo("messageId")) allMessages[0].apply {
assertThat(message, isEqualTo("Beam me up, Scotty.")) assertThat(id, isEqualTo("messageId"))
assertThat(roomId, isEqualTo("GENERAL")) assertThat(message, isEqualTo("Beam me up, Scotty."))
assertThat(roomId, isEqualTo("GENERAL"))
}
} }
} }
@Test @Test
fun `saveAll() should all saved messages`() { fun `saveAll() should all saved messages`() {
assertThat(repository.getAll().size, isEqualTo(0)) runBlocking {
repository.saveAll(listOf(msg, msg2)) assertThat(repository.getAll().size, isEqualTo(0))
val allMessages = repository.getAll() repository.saveAll(listOf(msg, msg2))
assertThat(allMessages.size, isEqualTo(2)) val allMessages = repository.getAll()
allMessages[0].apply { assertThat(allMessages.size, isEqualTo(2))
assertThat(id, isEqualTo("messageId")) allMessages[0].apply {
assertThat(message, isEqualTo("Beam me up, Scotty.")) assertThat(id, isEqualTo("messageId"))
assertThat(roomId, isEqualTo("GENERAL")) assertThat(message, isEqualTo("Beam me up, Scotty."))
} assertThat(roomId, isEqualTo("GENERAL"))
}
allMessages[1].apply { allMessages[1].apply {
assertThat(id, isEqualTo("messageId2")) assertThat(id, isEqualTo("messageId2"))
assertThat(message, isEqualTo("Highly Illogical")) assertThat(message, isEqualTo("Highly Illogical"))
assertThat(roomId, isEqualTo("sandbox")) assertThat(roomId, isEqualTo("sandbox"))
}
} }
} }
@Test @Test
fun `getById() should return a single message`() { fun `getById() should return a single message`() {
repository.saveAll(listOf(msg, msg2)) runBlocking {
var singleMsg = repository.getById("messageId") repository.saveAll(listOf(msg, msg2))
assertThat(singleMsg, notNullValue()) var singleMsg = repository.getById("messageId")
singleMsg!!.apply { assertThat(singleMsg, notNullValue())
assertThat(id, isEqualTo("messageId")) singleMsg!!.apply {
assertThat(message, isEqualTo("Beam me up, Scotty.")) assertThat(id, isEqualTo("messageId"))
assertThat(roomId, isEqualTo("GENERAL")) assertThat(message, isEqualTo("Beam me up, Scotty."))
} assertThat(roomId, isEqualTo("GENERAL"))
}
singleMsg = repository.getById("messageId2") singleMsg = repository.getById("messageId2")
assertThat(singleMsg, notNullValue()) assertThat(singleMsg, notNullValue())
singleMsg!!.apply { singleMsg!!.apply {
assertThat(id, isEqualTo("messageId2")) assertThat(id, isEqualTo("messageId2"))
assertThat(message, isEqualTo("Highly Illogical")) assertThat(message, isEqualTo("Highly Illogical"))
assertThat(roomId, isEqualTo("sandbox")) assertThat(roomId, isEqualTo("sandbox"))
}
} }
} }
@Test @Test
fun `getByRoomId() should return all messages for room id or an empty list`() { fun `getByRoomId() should return all messages for room id or an empty list`() {
repository.saveAll(listOf(msg, msg2)) runBlocking {
var roomMessages = repository.getByRoomId("faAad32fkasods2") repository.saveAll(listOf(msg, msg2))
assertThat(roomMessages.isEmpty(), isEqualTo(true)) var roomMessages = repository.getByRoomId("faAad32fkasods2")
assertThat(roomMessages.isEmpty(), isEqualTo(true))
roomMessages = repository.getByRoomId("sandbox") roomMessages = repository.getByRoomId("sandbox")
assertThat(roomMessages.size, isEqualTo(1)) assertThat(roomMessages.size, isEqualTo(1))
roomMessages[0].apply { roomMessages[0].apply {
assertThat(id, isEqualTo("messageId2")) assertThat(id, isEqualTo("messageId2"))
assertThat(message, isEqualTo("Highly Illogical")) assertThat(message, isEqualTo("Highly Illogical"))
assertThat(roomId, isEqualTo("sandbox")) assertThat(roomId, isEqualTo("sandbox"))
} }
roomMessages = repository.getByRoomId("GENERAL") roomMessages = repository.getByRoomId("GENERAL")
assertThat(roomMessages.size, isEqualTo(1)) assertThat(roomMessages.size, isEqualTo(1))
roomMessages[0].apply { roomMessages[0].apply {
assertThat(id, isEqualTo("messageId")) assertThat(id, isEqualTo("messageId"))
assertThat(message, isEqualTo("Beam me up, Scotty.")) assertThat(message, isEqualTo("Beam me up, Scotty."))
assertThat(roomId, isEqualTo("GENERAL")) assertThat(roomId, isEqualTo("GENERAL"))
}
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment