mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
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
|
// We emit Done in case the progress listener was deallocated before generate() sent the Done
|
||||||
_linkMobileStep.emit(LinkMobileStep.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) {
|
} catch (e: HumanQrGrantLoginException.NotFound) {
|
||||||
Timber.tag(tag.value).w(e, "Error during QR login grant")
|
Timber.tag(tag.value).w(e, "Error during QR login grant")
|
||||||
// Catch timeout here?
|
// 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(
|
private fun TestScope.createRustLinkMobileHandler(
|
||||||
handler: FakeFfiGrantLoginWithQrCodeHandler = FakeFfiGrantLoginWithQrCodeHandler(),
|
handler: FakeFfiGrantLoginWithQrCodeHandler = FakeFfiGrantLoginWithQrCodeHandler(),
|
||||||
) = RustLinkMobileHandler(
|
) = RustLinkMobileHandler(
|
||||||
|
|||||||
Reference in New Issue
Block a user