Skip to content

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

Merged
merged 37 commits into from
May 23, 2024
Merged

Add unit tests in some push classes #2899

merged 37 commits into from
May 23, 2024

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented May 22, 2024

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:

image

This does not fix any bug, except one related to log, so very minor.

bmarty and others added 30 commits May 22, 2024 09:23
We may properly add it again later if necessary.
Copy link

codecov bot commented May 22, 2024

Codecov Report

Attention: Patch coverage is 82.78689% with 21 lines in your changes are missing coverage. Please review.

Project coverage is 75.26%. Comparing base (7bda5fd) to head (788d9e0).
Report is 7 commits behind head on develop.

Files Patch % Lines
...nstorage/impl/memory/InMemoryMultiSessionsStore.kt 40.00% 6 Missing ⚠️
...ies/push/impl/pushgateway/PushGatewayApiFactory.kt 0.00% 4 Missing ⚠️
...pushproviders/unifiedpush/UnifiedPushApiFactory.kt 0.00% 4 Missing ⚠️
...libraries/push/impl/push/IncrementPushDataStore.kt 0.00% 3 Missing ⚠️
...raries/push/impl/push/OnNotifiableEventReceived.kt 0.00% 3 Missing ⚠️
...ries/pushproviders/unifiedpush/UnifiedPushStore.kt 0.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@bmarty bmarty added the Run-Maestro Starts a Maestro Cloud session to run integration tests label May 23, 2024
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label May 23, 2024
Copy link
Contributor

github-actions bot commented May 23, 2024

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/wbYzzA

@bmarty bmarty marked this pull request as ready for review May 23, 2024 07:16
@bmarty bmarty requested a review from a team as a code owner May 23, 2024 07:16
@bmarty bmarty requested review from jmartinesp and removed request for a team May 23, 2024 07:16
@jmartinesp jmartinesp force-pushed the feature/bma/unitTestPush branch from 174dea5 to 0639bc6 Compare May 23, 2024 07:57
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Member

@jmartinesp jmartinesp left a 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) {
Copy link
Member

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(
Copy link
Member

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(
Copy link
Member

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 {
Copy link
Member

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 {
Copy link
Member

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")
Copy link
Member

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 {
Copy link
Member

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 {
Copy link
Member

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)
Copy link
Member

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bmarty
Copy link
Member Author

bmarty commented May 23, 2024

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.
Let's merge the PR like this since as you said there is no blocker.
Thanks again for the review!

@bmarty bmarty merged commit 22bde9e into develop May 23, 2024
21 checks passed
@bmarty bmarty deleted the feature/bma/unitTestPush branch May 23, 2024 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants