feat(dm): recipientId 계약을 추가한다
This commit is contained in:
@@ -5,7 +5,8 @@ import com.google.gson.annotations.SerializedName
|
||||
|
||||
@Keep
|
||||
data class CreateDmChatRoomRequest(
|
||||
@SerializedName("creatorId") val creatorId: Long
|
||||
@SerializedName("recipientId") val recipientId: Long? = null,
|
||||
@SerializedName("creatorId") val creatorId: Long? = null
|
||||
)
|
||||
|
||||
@Keep
|
||||
|
||||
@@ -18,6 +18,14 @@ class DmChatRepository(
|
||||
request = CreateDmChatRoomRequest(creatorId = creatorId)
|
||||
)
|
||||
|
||||
fun createOrGetRoomByRecipientId(
|
||||
token: String,
|
||||
recipientId: Long
|
||||
): Single<ApiResponse<CreateDmChatRoomResponse>> = api.createDmChatRoom(
|
||||
authHeader = bearer(token),
|
||||
request = CreateDmChatRoomRequest(recipientId = recipientId)
|
||||
)
|
||||
|
||||
fun openRoom(
|
||||
token: String,
|
||||
roomId: Long,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package kr.co.vividnext.sodalive.v2.main.chat.dm
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonParser
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.v2.main.chat.dm.data.CreateDmChatRoomRequest
|
||||
@@ -27,6 +29,7 @@ import org.junit.Test
|
||||
|
||||
class DmChatRepositoryTest {
|
||||
|
||||
private val gson = Gson()
|
||||
private val api = FakeDmChatApi()
|
||||
private val socketFactory = FakeWebSocketFactory()
|
||||
private val socketClient = DmChatSocketClient(
|
||||
@@ -45,6 +48,32 @@ class DmChatRepositoryTest {
|
||||
assertEquals(CreateDmChatRoomRequest(creatorId = 11L), api.lastCreateRequest)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `리스너 DM 생성 request는 recipientId만 직렬화한다`() {
|
||||
val json = gson.toJson(CreateDmChatRoomRequest(recipientId = 22L))
|
||||
val jsonObject = JsonParser.parseString(json).asJsonObject
|
||||
|
||||
assertEquals(22L, jsonObject.get("recipientId").asLong)
|
||||
assertFalse(jsonObject.has("creatorId"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `createOrGetRoomByRecipientId는 bearer header와 recipientId를 API에 위임한다`() {
|
||||
repository.createOrGetRoomByRecipientId(token = "test-token", recipientId = 22L).blockingGet()
|
||||
|
||||
assertEquals("Bearer test-token", api.lastAuthHeader)
|
||||
assertEquals(CreateDmChatRoomRequest(recipientId = 22L), api.lastCreateRequest)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `크리에이터 채널 DM 생성 request는 creatorId만 직렬화한다`() {
|
||||
val json = gson.toJson(CreateDmChatRoomRequest(creatorId = 11L))
|
||||
val jsonObject = JsonParser.parseString(json).asJsonObject
|
||||
|
||||
assertEquals(11L, jsonObject.get("creatorId").asLong)
|
||||
assertFalse(jsonObject.has("recipientId"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `openRoom은 기본 limit 20과 bearer header를 API에 위임한다`() {
|
||||
repository.openRoom(token = "test-token", roomId = 12L).blockingGet()
|
||||
|
||||
Reference in New Issue
Block a user