Skip to content
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

[TECHNICAL] Unit tests for repository classes - Part 4 #4537

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

joragua
Copy link
Collaborator

@joragua joragua commented Jan 24, 2025

Related Issues

App:

  • Add changelog files for the fixed issues in folder changelog/unreleased. More info here
  • Add feature to Release Notes in ReleaseNotesViewModel.kt creating a new ReleaseNote() with String resources (if required)

QA

@joragua joragua self-assigned this Jan 24, 2025
@joragua joragua linked an issue Jan 24, 2025 that may be closed by this pull request
9 tasks
@joragua joragua marked this pull request as draft January 24, 2025 09:56
@joragua joragua force-pushed the technical/testing_repositories_4 branch 2 times, most recently from 2f77fbb to cd05b19 Compare January 28, 2025 09:42
@joragua joragua marked this pull request as ready for review January 29, 2025 11:34
@joragua joragua requested a review from JuancaG05 January 29, 2025 11:35
Copy link
Collaborator

@JuancaG05 JuancaG05 left a comment

Choose a reason for hiding this comment

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

Some changes requested here @joragua! 👍

Comment on lines +40 to +54
val OC_USER_QUOTA_WITHOUT_PERSONAL = UserQuota(
accountName = OC_ACCOUNT_NAME,
used = 0,
available = -4L,
total = 0,
state = UserQuotaState.NORMAL
)

val OC_USER_QUOTA_UNLIMITED = UserQuota(
accountName = OC_ACCOUNT_NAME,
used = 5_000,
available = -3L,
total = 0,
state = UserQuotaState.NORMAL
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be clearer if you wrote the parameters in the same order as in the implementation: accountName, available, used, total and state, like that. That way, when we want to compare with the implementation, it will be a direct mapping 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done ✅

fun `getSpaceByIdForAccount returns an OCSpace`() {
every {
localSpacesDataSource.getSpaceByIdForAccount(OC_SPACE_PROJECT_WITH_IMAGE.id, OC_ACCOUNT_NAME)
} returns OC_SPACE_PROJECT_WITH_IMAGE
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one has specials in it. Check if there is any other example space that has no specials and use it, otherwise the content of this test (and the method) is the same as the previous one

}

@Test
fun `updateTransferStatusToInProgressById updates a transfer in progress by its id correctly`() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

More than updating a transfer in progress, this is intended to update a transfer's status to "in progress", so you could mention that the status is changed (check OCLocalTransferDataSourceTest)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed 👍🏻

}

@Test
fun `updateTransferStatusToEnqueuedById updates a transfer in queue by its id correctly`() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as the previous test

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

}

@Test
fun `updateTransferWhenFinished updates a finished transfer correctly `() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
fun `updateTransferWhenFinished updates a finished transfer correctly `() {
fun `updateTransferWhenFinished updates a finished transfer correctly`() {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

}

@Test
fun `getCurrentAndPendingTransfers returns a list of pending and in progress OCTransfer`() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
fun `getCurrentAndPendingTransfers returns a list of pending and in progress OCTransfer`() {
fun `getCurrentAndPendingTransfers returns a list of OCTransfer`() {

No need to specify semantically if not needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed!

Comment on lines +116 to 128
@Test
fun `getStoredUserQuotaAsFlow returns a Flow with null when local datasource returns a Flow with null`() = runTest {
every {
localUserDataSource.getQuotaForAccountAsFlow(OC_ACCOUNT_NAME)
} returns flowOf(null)

val userQuota = ocUserRepository.getStoredUserQuotaAsFlow(OC_ACCOUNT_NAME).first()
assertNull(userQuota)

ocUserRepository.getStoredUserQuota(OC_ACCOUNT_NAME)
verify(exactly = 1) {
localUserDataSource.getQuotaForAccountAsFlow(OC_ACCOUNT_NAME)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not needed

*
* @author Jorge Aguado Recio
*
* Copyright (C) 2024 ownCloud GmbH.
Copy link
Collaborator

Choose a reason for hiding this comment

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

BTW, it's already 2025 🙂

remoteWebFingerDatasource.getInstancesFromWebFinger(
OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl,
WebFingerRel.OIDC_ISSUER_DISCOVERY,
OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl
Copy link
Collaborator

Choose a reason for hiding this comment

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

The resource is usually the webfinger username. You can adapt this so that it looks a bit more realistic 👍

remoteWebFingerDatasource.getInstancesFromAuthenticatedWebFinger(
OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl,
WebFingerRel.OIDC_ISSUER_DISCOVERY,
OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This also has a different structure. Check GetOwnCloudInstancesFromAuthenticatedWebFingerUseCase

@joragua joragua force-pushed the technical/testing_repositories_4 branch from d15020c to 4f1701a Compare February 4, 2025 10:16
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.

[TECHNICAL] Unit tests for repository classes - Part 4
2 participants