fix(member-info): 구서버 멤버정보 누락 필드 하위 호환을 보장한다
This commit is contained in:
@@ -13,6 +13,7 @@ import kr.co.vividnext.sodalive.audio_content.PlaybackTrackingData
|
||||
import kr.co.vividnext.sodalive.audio_content.PlaybackTrackingRepository
|
||||
import kr.co.vividnext.sodalive.base.BaseViewModel
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.settings.ContentType
|
||||
import kr.co.vividnext.sodalive.settings.event.EventItem
|
||||
import kr.co.vividnext.sodalive.settings.event.EventRepository
|
||||
import kr.co.vividnext.sodalive.settings.notification.UpdateNotificationSettingRequest
|
||||
@@ -103,9 +104,19 @@ class MainViewModel(
|
||||
SharedPreferenceManager.point = data.point
|
||||
SharedPreferenceManager.role = data.role.name
|
||||
SharedPreferenceManager.isAuth = data.isAuth
|
||||
SharedPreferenceManager.countryCode = data.countryCode.ifBlank { "KR" }
|
||||
SharedPreferenceManager.isAdultContentVisible = data.isAdultContentVisible
|
||||
SharedPreferenceManager.contentPreference = data.contentType.ordinal
|
||||
|
||||
val localCountryCode = SharedPreferenceManager.countryCode.ifBlank { "KR" }
|
||||
val resolvedCountryCode = data.countryCode?.ifBlank { "KR" } ?: localCountryCode
|
||||
val resolvedIsAdultContentVisible =
|
||||
data.isAdultContentVisible ?: SharedPreferenceManager.isAdultContentVisible
|
||||
val resolvedContentType =
|
||||
data.contentType
|
||||
?: ContentType.entries.getOrNull(SharedPreferenceManager.contentPreference)
|
||||
?: ContentType.ALL
|
||||
|
||||
SharedPreferenceManager.countryCode = resolvedCountryCode
|
||||
SharedPreferenceManager.isAdultContentVisible = resolvedIsAdultContentVisible
|
||||
SharedPreferenceManager.contentPreference = resolvedContentType.ordinal
|
||||
SharedPreferenceManager.isAuditionNotification =
|
||||
data.auditionNotice ?: false
|
||||
if (
|
||||
|
||||
@@ -21,11 +21,11 @@ data class GetMemberInfoResponse(
|
||||
@SerializedName("auditionNotice")
|
||||
val auditionNotice: Boolean?,
|
||||
@SerializedName("countryCode")
|
||||
val countryCode: String,
|
||||
val countryCode: String? = null,
|
||||
@SerializedName("isAdultContentVisible")
|
||||
val isAdultContentVisible: Boolean,
|
||||
val isAdultContentVisible: Boolean? = null,
|
||||
@SerializedName("contentType")
|
||||
val contentType: ContentType
|
||||
val contentType: ContentType? = null
|
||||
)
|
||||
|
||||
enum class MemberRole {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package kr.co.vividnext.sodalive.settings.notification
|
||||
|
||||
import com.google.gson.Gson
|
||||
import kr.co.vividnext.sodalive.settings.ContentType
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class GetMemberInfoResponseCompatibilityTest {
|
||||
|
||||
private val gson = Gson()
|
||||
|
||||
@Test
|
||||
fun `구서버 응답에서 신규 필드가 없어도 역직렬화된다`() {
|
||||
val json = """
|
||||
{
|
||||
"can": 10,
|
||||
"point": 120,
|
||||
"isAuth": true,
|
||||
"gender": "F",
|
||||
"signupDate": "2024-01-01, 00:00:00",
|
||||
"chargeCount": 3,
|
||||
"role": "USER",
|
||||
"messageNotice": true,
|
||||
"followingChannelLiveNotice": false,
|
||||
"followingChannelUploadContentNotice": true,
|
||||
"auditionNotice": false
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val response = gson.fromJson(json, GetMemberInfoResponse::class.java)
|
||||
|
||||
assertEquals(10, response.can)
|
||||
assertEquals(120, response.point)
|
||||
assertTrue(response.isAuth)
|
||||
assertEquals(MemberRole.USER, response.role)
|
||||
assertNull(response.countryCode)
|
||||
assertNull(response.isAdultContentVisible)
|
||||
assertNull(response.contentType)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `신규 필드가 있으면 정상 매핑된다`() {
|
||||
val json = """
|
||||
{
|
||||
"can": 10,
|
||||
"point": 120,
|
||||
"isAuth": true,
|
||||
"gender": "F",
|
||||
"signupDate": "2024-01-01, 00:00:00",
|
||||
"chargeCount": 3,
|
||||
"role": "CREATOR",
|
||||
"messageNotice": true,
|
||||
"followingChannelLiveNotice": false,
|
||||
"followingChannelUploadContentNotice": true,
|
||||
"auditionNotice": false,
|
||||
"countryCode": "US",
|
||||
"isAdultContentVisible": true,
|
||||
"contentType": "FEMALE"
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val response = gson.fromJson(json, GetMemberInfoResponse::class.java)
|
||||
|
||||
assertEquals("US", response.countryCode)
|
||||
assertEquals(true, response.isAdultContentVisible)
|
||||
assertEquals(ContentType.FEMALE, response.contentType)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user