Ensure that the application rotate the QrCode if one day the SDK emits the .Expired error. (#6993)
This commit is contained in:
+4
@@ -51,6 +51,10 @@ class RustLinkMobileHandler(
|
||||
)
|
||||
// We emit Done in case the progress listener was deallocated before generate() sent the Done
|
||||
_linkMobileStep.emit(LinkMobileStep.Done)
|
||||
} catch (e: HumanQrGrantLoginException.Expired) {
|
||||
// Note: the SDK does not return this error, but is returning `.NotFound` instead when the QR code expires. We catch both just in case.
|
||||
Timber.tag(tag.value).w(e, "QR code has expired")
|
||||
_linkMobileStep.emit(LinkMobileStep.QrRotating)
|
||||
} catch (e: HumanQrGrantLoginException.NotFound) {
|
||||
Timber.tag(tag.value).w(e, "Error during QR login grant")
|
||||
// Catch timeout here?
|
||||
|
||||
+26
@@ -147,6 +147,32 @@ class RustLinkMobileHandlerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when start throws HumanQrGrantLoginException_Expired, the handler emits QrRotating step`() = runTest {
|
||||
val completable = CompletableDeferred<Unit>()
|
||||
val handler = FakeFfiGrantLoginWithQrCodeHandler(
|
||||
generateResult = {
|
||||
completable.await()
|
||||
throw HumanQrGrantLoginException.Expired("Expired")
|
||||
}
|
||||
)
|
||||
val sut = createRustLinkMobileHandler(
|
||||
handler,
|
||||
)
|
||||
sut.linkMobileStep.test {
|
||||
val initialItem = awaitItem()
|
||||
assertThat(initialItem).isEqualTo(LinkMobileStep.Uninitialized)
|
||||
backgroundScope.launch {
|
||||
sut.start()
|
||||
}
|
||||
runCurrent()
|
||||
// generate returns, error is emitted
|
||||
completable.complete(Unit)
|
||||
val qrRotatingState = awaitItem()
|
||||
assertThat(qrRotatingState).isEqualTo(LinkMobileStep.QrRotating)
|
||||
}
|
||||
}
|
||||
|
||||
private fun TestScope.createRustLinkMobileHandler(
|
||||
handler: FakeFfiGrantLoginWithQrCodeHandler = FakeFfiGrantLoginWithQrCodeHandler(),
|
||||
) = RustLinkMobileHandler(
|
||||
|
||||
Reference in New Issue
Block a user