feat(auth): 본인인증 종료 흐름과 전환 보정을 추가한다
This commit is contained in:
+22
-1
@@ -9,6 +9,7 @@ import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.settings.ContentType
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.Robolectric
|
||||
@@ -29,7 +30,7 @@ class ContentPreferenceBottomSheetTest {
|
||||
sheet = ContentPreferenceBottomSheet(controller.get(), {}, {}, {
|
||||
assertFalse(sheet.isShowing)
|
||||
confirmations += 1
|
||||
})
|
||||
}, {})
|
||||
sheet.render(true, ContentType.FEMALE, selectionEnabled = false)
|
||||
sheet.show()
|
||||
val confirm = sheet.findViewById<View>(R.id.btn_confirm)!!
|
||||
@@ -45,4 +46,24 @@ class ContentPreferenceBottomSheetTest {
|
||||
sheet.dismiss()
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `닫기 터치는 제출 없이 종료 콜백만 전달한다`() {
|
||||
val controller = Robolectric.buildActivity(AppCompatActivity::class.java)
|
||||
controller.get().setTheme(R.style.Theme_SodaLive)
|
||||
controller.setup()
|
||||
var closes = 0
|
||||
var confirmations = 0
|
||||
val sheet = ContentPreferenceBottomSheet(controller.get(), {}, {}, { confirmations++ }, { closes++ })
|
||||
sheet.render(true, ContentType.ALL, selectionEnabled = true)
|
||||
sheet.show()
|
||||
|
||||
sheet.findViewById<View>(R.id.btn_close)!!.performClick()
|
||||
|
||||
assertEquals(1, closes)
|
||||
assertEquals(0, confirmations)
|
||||
assertTrue(sheet.isShowing)
|
||||
sheet.dismiss()
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.os.Bundle
|
||||
import android.os.Looper
|
||||
import android.os.Parcel
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
@@ -172,6 +173,225 @@ class V2AuthFlowTest {
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `인증 종료 모달 취소는 선택을 보존하고 확인은 POST 없이 흐름을 종료한다`() {
|
||||
listOf(false, true).forEach { syncMemberInfo ->
|
||||
val controller = Robolectric.buildActivity(AuthFlowHost::class.java).setup()
|
||||
val host = controller.get()
|
||||
SharedPreferenceManager.isAdultContentVisible = true
|
||||
SharedPreferenceManager.contentPreference = ContentType.MALE.ordinal
|
||||
SharedPreferenceManager.isAuth = false
|
||||
V2AuthFlow.start(host, syncMemberInfo)
|
||||
receiveReceipt()
|
||||
val original = flow(host)
|
||||
val originalModel = model(original)
|
||||
originalModel.selectContentType(ContentType.FEMALE)
|
||||
val sheet = ShadowDialog.getLatestDialog()
|
||||
sheet.findViewById<View>(R.id.btn_close).performClick()
|
||||
val cancelDialog = ShadowDialog.getLatestDialog()
|
||||
sheet.findViewById<View>(R.id.btn_close).performClick()
|
||||
assertSame(cancelDialog, ShadowDialog.getLatestDialog())
|
||||
val title = (cancelDialog.findViewById<View>(R.id.tv_title) as TextView).text.toString()
|
||||
val description = (cancelDialog.findViewById<View>(R.id.tv_desc) as TextView).text.toString()
|
||||
assertEquals(host.getString(R.string.v2_auth_close_title), title)
|
||||
assertEquals(host.getString(R.string.v2_auth_close_description), description)
|
||||
cancelDialog.findViewById<View>(R.id.tv_cancel).performClick()
|
||||
assertFalse(cancelDialog.isShowing)
|
||||
assertSame(original, flow(host))
|
||||
assertEquals(ContentType.FEMALE, originalModel.stateLiveData.value!!.contentType)
|
||||
assertTrue(requests.isEmpty())
|
||||
assertTrue(sheet.isShowing)
|
||||
|
||||
sheet.findViewById<View>(R.id.btn_close).performClick()
|
||||
val confirmDialog = ShadowDialog.getLatestDialog()
|
||||
assertNotSame(cancelDialog, confirmDialog)
|
||||
val confirm = confirmDialog.findViewById<View>(R.id.tv_confirm)
|
||||
confirm.performClick()
|
||||
confirm.performClick()
|
||||
ioScheduler.triggerActions()
|
||||
idle()
|
||||
assertTrue(host.supportFragmentManager.fragments.none { it is V2AuthFlow })
|
||||
assertTrue(requests.isEmpty())
|
||||
assertEquals(0, host.audioResults)
|
||||
assertFalse(host.isFinishing)
|
||||
assertFalse(confirmDialog.isShowing)
|
||||
assertFalse(sheet.isShowing)
|
||||
assertTrue(originalModel.compositeDisposable.isDisposed)
|
||||
assertTrue(SharedPreferenceManager.isAdultContentVisible)
|
||||
assertEquals(ContentType.MALE.ordinal, SharedPreferenceManager.contentPreference)
|
||||
assertFalse(SharedPreferenceManager.isAuth)
|
||||
assertNull(shadowOf(host).nextStartedActivity)
|
||||
|
||||
val oldCallback = callbacks.last()
|
||||
V2AuthFlow.start(host, syncMemberInfo)
|
||||
receiveReceipt()
|
||||
val freshFlow = flow(host)
|
||||
assertTrue(model(freshFlow).stateLiveData.value!!.isAdultContentVisible)
|
||||
assertEquals(ContentType.ALL, model(freshFlow).stateLiveData.value!!.contentType)
|
||||
oldCallback("{\"data\":{\"receipt_id\":\"late-receipt\"}}")
|
||||
idle()
|
||||
assertSame(freshFlow, flow(host))
|
||||
assertEquals(0, host.audioResults)
|
||||
assertEquals(0, memberCalls)
|
||||
assertTrue(requests.isEmpty())
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `종료 모달은 정지와 재생성에서 닫히고 선택 흐름을 유지한다`() {
|
||||
val controller = Robolectric.buildActivity(AuthFlowHost::class.java).setup()
|
||||
val host = controller.get()
|
||||
V2AuthFlow.start(host)
|
||||
receiveReceipt()
|
||||
val originalModel = model(flow(host))
|
||||
originalModel.selectContentType(ContentType.FEMALE)
|
||||
val oldSheet = ShadowDialog.getLatestDialog()
|
||||
oldSheet.findViewById<View>(R.id.btn_close).performClick()
|
||||
val oldPopup = ShadowDialog.getLatestDialog()
|
||||
|
||||
controller.pause().stop()
|
||||
assertFalse(oldSheet.isShowing)
|
||||
assertFalse(oldPopup.isShowing)
|
||||
controller.start().resume()
|
||||
idle()
|
||||
val resumedSheet = ShadowDialog.getLatestDialog()
|
||||
assertTrue(resumedSheet is ContentPreferenceBottomSheet)
|
||||
assertTrue(resumedSheet.isShowing)
|
||||
assertNotSame(oldSheet, resumedSheet)
|
||||
assertSame(originalModel, model(flow(host)))
|
||||
assertEquals(ContentType.FEMALE, originalModel.stateLiveData.value!!.contentType)
|
||||
resumedSheet.findViewById<View>(R.id.btn_close).performClick()
|
||||
val recreationPopup = ShadowDialog.getLatestDialog()
|
||||
|
||||
val recreatedHost = controller.recreate().get()
|
||||
idle()
|
||||
assertFalse(recreationPopup.isShowing)
|
||||
assertFalse(resumedSheet.isShowing)
|
||||
assertSame(originalModel, model(flow(recreatedHost)))
|
||||
assertEquals(ContentType.FEMALE, originalModel.stateLiveData.value!!.contentType)
|
||||
val recreatedSheet = ShadowDialog.getLatestDialog()
|
||||
assertTrue(recreatedSheet is ContentPreferenceBottomSheet)
|
||||
recreatedSheet.findViewById<View>(R.id.btn_close).performClick()
|
||||
assertTrue(ShadowDialog.getLatestDialog().isShowing)
|
||||
assertTrue(requests.isEmpty())
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `POST 실패 상태에서도 인증 종료는 추가 요청이나 설정 저장 없이 흐름을 종료한다`() {
|
||||
listOf(false, true).forEach { syncMemberInfo ->
|
||||
val controller = Robolectric.buildActivity(AuthFlowHost::class.java).setup()
|
||||
val host = controller.get()
|
||||
SharedPreferenceManager.isAdultContentVisible = true
|
||||
SharedPreferenceManager.contentPreference = ContentType.ALL.ordinal
|
||||
SharedPreferenceManager.isAuth = true
|
||||
V2AuthFlow.start(host, syncMemberInfo)
|
||||
receiveReceipt()
|
||||
val model = model(flow(host))
|
||||
model.selectContentType(ContentType.MALE)
|
||||
postSuccess = false
|
||||
ShadowDialog.getLatestDialog().findViewById<View>(R.id.btn_confirm).performClick()
|
||||
ioScheduler.triggerActions()
|
||||
assertEquals(V2AuthPhase.Failed, model.stateLiveData.value!!.phase)
|
||||
val callsBeforeClose = requests.size
|
||||
val savedPreference = SharedPreferenceManager.contentPreference
|
||||
val savedVisibility = SharedPreferenceManager.isAdultContentVisible
|
||||
val savedAuth = SharedPreferenceManager.isAuth
|
||||
|
||||
val failedSheet = ShadowDialog.getLatestDialog()
|
||||
failedSheet.findViewById<View>(R.id.btn_close).performClick()
|
||||
val cancelPopup = ShadowDialog.getLatestDialog()
|
||||
cancelPopup.findViewById<View>(R.id.tv_cancel).performClick()
|
||||
assertFalse(cancelPopup.isShowing)
|
||||
assertTrue(failedSheet is ContentPreferenceBottomSheet)
|
||||
assertTrue(failedSheet.isShowing)
|
||||
assertEquals(ContentType.MALE, model.stateLiveData.value!!.contentType)
|
||||
failedSheet.findViewById<View>(R.id.btn_close).performClick()
|
||||
ShadowDialog.getLatestDialog().findViewById<View>(R.id.tv_confirm).performClick()
|
||||
ioScheduler.triggerActions()
|
||||
idle()
|
||||
|
||||
assertTrue(host.supportFragmentManager.fragments.none { it is V2AuthFlow })
|
||||
assertEquals(callsBeforeClose, requests.size)
|
||||
assertEquals(savedPreference, SharedPreferenceManager.contentPreference)
|
||||
assertEquals(savedVisibility, SharedPreferenceManager.isAdultContentVisible)
|
||||
assertEquals(savedAuth, SharedPreferenceManager.isAuth)
|
||||
assertEquals(0, host.audioResults)
|
||||
assertEquals(0, memberCalls)
|
||||
assertFalse(host.isFinishing)
|
||||
assertNull(shadowOf(host).nextStartedActivity)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `회원 GET 실패로 잠긴 오디오 선택도 종료하면 추가 요청이나 저장 없이 닫힌다`() {
|
||||
val controller = Robolectric.buildActivity(AuthFlowHost::class.java).setup()
|
||||
val host = controller.get()
|
||||
SharedPreferenceManager.isAdultContentVisible = true
|
||||
SharedPreferenceManager.contentPreference = ContentType.MALE.ordinal
|
||||
SharedPreferenceManager.isAuth = true
|
||||
V2AuthFlow.start(host, true)
|
||||
receiveReceipt()
|
||||
val model = model(flow(host))
|
||||
model.selectContentType(ContentType.FEMALE)
|
||||
ShadowDialog.getLatestDialog().findViewById<View>(R.id.btn_confirm).performClick()
|
||||
ioScheduler.triggerActions()
|
||||
assertEquals(1, requests.size)
|
||||
assertEquals(1, memberCalls)
|
||||
member.onError(IllegalStateException("member fetch failed"))
|
||||
assertEquals(V2AuthPhase.Failed, model.stateLiveData.value!!.phase)
|
||||
assertTrue(model.stateLiveData.value!!.selectionLocked)
|
||||
val sheet = ShadowDialog.getLatestDialog()
|
||||
sheet.findViewById<View>(R.id.btn_close).performClick()
|
||||
ShadowDialog.getLatestDialog().findViewById<View>(R.id.tv_confirm).performClick()
|
||||
ioScheduler.triggerActions()
|
||||
idle()
|
||||
assertTrue(host.supportFragmentManager.fragments.none { it is V2AuthFlow })
|
||||
assertTrue(model.compositeDisposable.isDisposed)
|
||||
assertEquals(1, requests.size)
|
||||
assertEquals(1, memberCalls)
|
||||
assertTrue(SharedPreferenceManager.isAdultContentVisible)
|
||||
assertEquals(ContentType.MALE.ordinal, SharedPreferenceManager.contentPreference)
|
||||
assertTrue(SharedPreferenceManager.isAuth)
|
||||
assertEquals(0, host.audioResults)
|
||||
assertNull(shadowOf(host).nextStartedActivity)
|
||||
assertFalse(host.isFinishing)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `디버그 인증 종료 후 재진입은 서버 요청 없이 기본 선택을 다시 시작한다`() {
|
||||
val controller = Robolectric.buildActivity(AuthFlowHost::class.java).setup()
|
||||
val host = controller.get()
|
||||
SharedPreferenceManager.contentPreference = ContentType.MALE.ordinal
|
||||
SharedPreferenceManager.isAdultContentVisible = false
|
||||
startDebug(host)
|
||||
advance(500)
|
||||
val oldFlow = flow(host)
|
||||
val oldModel = model(oldFlow)
|
||||
ShadowDialog.getLatestDialog().findViewById<View>(R.id.btn_close).performClick()
|
||||
val popup = ShadowDialog.getLatestDialog()
|
||||
popup.findViewById<View>(R.id.tv_confirm).performClick()
|
||||
idle()
|
||||
assertFalse(popup.isShowing)
|
||||
assertTrue(oldModel.compositeDisposable.isDisposed)
|
||||
assertTrue(host.supportFragmentManager.fragments.none { it is V2AuthFlow })
|
||||
assertTrue(requests.isEmpty())
|
||||
assertTrue(callbacks.isEmpty())
|
||||
assertEquals(ContentType.MALE.ordinal, SharedPreferenceManager.contentPreference)
|
||||
assertFalse(SharedPreferenceManager.isAdultContentVisible)
|
||||
assertEquals(0, host.audioResults)
|
||||
assertNull(shadowOf(host).nextStartedActivity)
|
||||
startDebug(host)
|
||||
advance(500)
|
||||
val freshState = model(flow(host)).stateLiveData.value!!
|
||||
assertTrue(freshState.isAdultContentVisible)
|
||||
assertEquals(ContentType.ALL, freshState.contentType)
|
||||
controller.pause().stop().destroy()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `중복 SDK 성공은 완료 전후에도 세션과 요청을 한 번만 만들고 새 인증은 별도 세션이다`() {
|
||||
val controller = Robolectric.buildActivity(AuthFlowHost::class.java).setup()
|
||||
|
||||
Reference in New Issue
Block a user