-
Notifications
You must be signed in to change notification settings - Fork 226
Add unit tests in some push classes #2899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
We may properly add it again later if necessary.
…tPusherSubscriber
… it's acting as a key.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #2899 +/- ##
===========================================
+ Coverage 74.21% 75.26% +1.04%
===========================================
Files 1540 1550 +10
Lines 36892 36917 +25
Branches 7149 7148 -1
===========================================
+ Hits 27381 27784 +403
+ Misses 5779 5398 -381
- Partials 3732 3735 +3 ☔ View full report in Codecov by Sentry. |
📱 Scan the QR code below to install the build (arm64 only) for this PR. |
…ambda is invoked and it should not.
174dea5
to
0639bc6
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work on this and the big coverage increase! I added lots of small comments (especially about docs), but none of them are really blockers, so feel free to merge it as is.
@@ -48,6 +50,9 @@ class FakeAuthenticationService : MatrixAuthenticationService { | |||
override suspend fun getLatestSessionId(): SessionId? = getLatestSessionIdLambda() | |||
|
|||
override suspend fun restoreSession(sessionId: SessionId): Result<MatrixClient> { | |||
if (matrixClientResult != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally it would be nice to use matrixClientResult
here to the get MatrixClient
instead of having 2 sources of truth, but changing it may not be worth it.
} | ||
|
||
@ContributesBinding(AppScope::class) | ||
class DefaultNotifiableEventResolver @Inject constructor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move this to a separate file in the api module?
} | ||
|
||
@ContributesBinding(AppScope::class) | ||
class DefaultOnNotifiableEventReceived @Inject constructor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could move this to its own file, maybe.
import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent | ||
import javax.inject.Inject | ||
|
||
interface OnNotifiableEventReceived { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs?
import io.element.android.libraries.push.impl.store.DefaultPushDataStore | ||
import javax.inject.Inject | ||
|
||
interface IncrementPushDataStore { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs?
val port = if (url.port != -1) ":${url.port}" else "" | ||
val customBase = "${url.protocol}://${url.host}$port" | ||
val customUrl = "$customBase/_matrix/push/v1/notify" | ||
Timber.i("Testing $customUrl") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we re-throw CancellationExceptions
?
|
||
/** | ||
* Handle new endpoint received from UnifiedPush. Will update the session matching the client secret. | ||
*/ | ||
class UnifiedPushNewGatewayHandler @Inject constructor( | ||
interface UnifiedPushNewGatewayHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split this into 2 files?
import io.element.android.libraries.di.ApplicationContext | ||
import io.element.android.libraries.di.DefaultPreferences | ||
import io.element.android.libraries.matrix.api.core.UserId | ||
import javax.inject.Inject | ||
|
||
class UnifiedPushStore @Inject constructor( | ||
interface UnifiedPushStore { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs + splitting?
suspend fun execute(matrixClient: MatrixClient, clientSecret: String): Result<Unit> | ||
} | ||
|
||
@ContributesBinding(AppScope::class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs + splitting?
@@ -164,7 +164,7 @@ internal fun MentionSpanPreview() { | |||
eventId = null, | |||
viaParameters = persistentListOf(), | |||
) | |||
else -> TODO() | |||
else -> throw AssertionError("Unexpected value $uriString") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thanks for the review. About splitting interface and default implementation, I think it does not worth it as the interface in only to ease the unit tests. so it's actually fine to me if the interface (which does not need to be expose in a api module) and the default impl is in the same file. |
Add unit tests in some push classes
I had to introduce some interface to be able to properly unit test more classes.
Code coverage is doing a nice bump:
This does not fix any bug, except one related to log, so very minor.