-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[JP Content Migration Flow] Check Wordpress version compatibility #17536
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cedc3b7
Check if WordPress app exists
f884a32
Check if WordPress app is compatible
f031cdf
Adds tests for the semantic version stripping mechanism
45d6148
Fixes package version unit test
9e4b7db
Adds unit tests for Jetpack migration flow eligibility criteria
5be5a6c
Adds check for null WordPress version
398ff12
Adds explicit return type
02fec9c
Use regex to clean up semantic version string
3b8c9a7
Fixes detekt issus with many return statemenents
a532bab
Fixes checkstyle issue
6dd4699
Fixes broken test due to the validation change
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 77 additions & 1 deletion
78
WordPress/src/test/java/org/wordpress/android/sharedlogin/WordPressPublicDataTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,92 @@ | ||
package org.wordpress.android.sharedlogin | ||
|
||
import android.content.pm.PackageInfo | ||
import org.assertj.core.api.Assertions | ||
import org.junit.Test | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.whenever | ||
import org.wordpress.android.util.publicdata.PackageManagerWrapper | ||
import org.wordpress.android.util.publicdata.WordPressPublicData | ||
|
||
class WordPressPublicDataTest { | ||
private val classToTest = WordPressPublicData() | ||
private val packageManagerWrapper: PackageManagerWrapper = mock() | ||
|
||
private val classToTest = WordPressPublicData(packageManagerWrapper) | ||
|
||
@Test | ||
fun `Should return correct current package ID`() { | ||
val actual = classToTest.currentPackageId() | ||
val expected = "org.wordpress.android" | ||
Assertions.assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `Should return correct current package version`() { | ||
mockVersion("21.2-rc-3") | ||
val actual = classToTest.currentPackageVersion() | ||
val expected = "21.2-rc-3" | ||
Assertions.assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `Versions without semantic information should be equal to the non semantic version`() { | ||
mockVersion("21.2") | ||
val actual = classToTest.nonSemanticPackageVersion() | ||
val expected = "21.2" | ||
Assertions.assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `Release candidate versions should be stripped from the non semantic version`() { | ||
mockVersion("21.2-rc-3") | ||
val actual = classToTest.nonSemanticPackageVersion() | ||
val expected = "21.2" | ||
Assertions.assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `Alpha versions should be stripped from the non semantic version`() { | ||
mockVersion("21.2-alpha-3") | ||
val actual = classToTest.nonSemanticPackageVersion() | ||
val expected = "21.2" | ||
Assertions.assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `Invalid versions should return a null non semantic version`() { | ||
mockVersion("21.a2...-rc2") | ||
val actual = classToTest.nonSemanticPackageVersion() | ||
val expected = null | ||
Assertions.assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `Empty versions should return a null non semantic version`() { | ||
mockVersion("") | ||
val actual = classToTest.nonSemanticPackageVersion() | ||
val expected = null | ||
Assertions.assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `Only the major-minor version information is returned`() { | ||
mockVersion("21.3.1") | ||
val actual = classToTest.nonSemanticPackageVersion() | ||
val expected = "21.3" | ||
Assertions.assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
@Test | ||
fun `When only the major is provided a null non semantic version is returned`() { | ||
mockVersion("21") | ||
val actual = classToTest.nonSemanticPackageVersion() | ||
val expected = null | ||
Assertions.assertThat(actual).isEqualTo(expected) | ||
} | ||
|
||
private fun mockVersion(version: String) { | ||
val packageInfo = PackageInfo().apply { versionName = version } | ||
whenever(packageManagerWrapper.getPackageInfo(any(), any())).thenReturn(packageInfo) | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
WordPress/src/test/java/org/wordpress/android/ui/utils/JetpackAppMigrationFlowUtilsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package org.wordpress.android.ui.utils | ||
|
||
import org.junit.Assert | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.junit.MockitoJUnitRunner | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.whenever | ||
import org.wordpress.android.fluxc.store.AccountStore | ||
import org.wordpress.android.ui.prefs.AppPrefsWrapper | ||
import org.wordpress.android.util.BuildConfigWrapper | ||
import org.wordpress.android.util.config.JetpackMigrationFlowFeatureConfig | ||
import org.wordpress.android.util.publicdata.AppStatus | ||
import org.wordpress.android.util.publicdata.WordPressPublicData | ||
import org.wordpress.android.viewmodel.ContextProvider | ||
|
||
@RunWith(MockitoJUnitRunner::class) | ||
class JetpackAppMigrationFlowUtilsTest { | ||
private val buildConfigWrapper: BuildConfigWrapper = mock() | ||
private val jetpackMigrationFlowFeatureConfig: JetpackMigrationFlowFeatureConfig = mock() | ||
private val contextProvider: ContextProvider = mock() | ||
private val appPrefsWrapper: AppPrefsWrapper = mock() | ||
private val accountStore: AccountStore = mock() | ||
private val appStatus: AppStatus = mock() | ||
private val wordPressPublicData: WordPressPublicData = mock() | ||
|
||
private val jetpackAppMigrationFlowUtils = JetpackAppMigrationFlowUtils( | ||
buildConfigWrapper, | ||
jetpackMigrationFlowFeatureConfig, | ||
contextProvider, | ||
appPrefsWrapper, | ||
accountStore, | ||
appStatus, | ||
wordPressPublicData | ||
) | ||
|
||
@Before | ||
fun setUp() { | ||
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true) | ||
whenever(jetpackMigrationFlowFeatureConfig.isEnabled()).thenReturn(true) | ||
whenever(appPrefsWrapper.getIsFirstTrySharedLoginJetpack()).thenReturn(true) | ||
whenever(accountStore.hasAccessToken()).thenReturn(false) | ||
whenever(wordPressPublicData.currentPackageId()).thenReturn("package") | ||
whenever(appStatus.isAppInstalled(any())).thenReturn(true) | ||
whenever(wordPressPublicData.nonSemanticPackageVersion()).thenReturn("21.3") | ||
} | ||
|
||
@Test | ||
fun `When all conditions are met the migration flow should be shown`() { | ||
val expected = true | ||
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow() | ||
Assert.assertEquals(expected, actual) | ||
} | ||
|
||
@Test | ||
fun `When not in the Jetpack app the migration flow should not be shown`() { | ||
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false) | ||
val expected = false | ||
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow() | ||
Assert.assertEquals(expected, actual) | ||
} | ||
|
||
@Test | ||
fun `When the jetpackMigrationFlow is not enableed the Jetpack app the migration flow should not be shown`() { | ||
whenever(jetpackMigrationFlowFeatureConfig.isEnabled()).thenReturn(false) | ||
val expected = false | ||
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow() | ||
Assert.assertEquals(expected, actual) | ||
} | ||
|
||
@Test | ||
fun `When the it is not the first migration attempt the Jetpack app the migration flow should not be shown`() { | ||
whenever(appPrefsWrapper.getIsFirstTrySharedLoginJetpack()).thenReturn(false) | ||
val expected = false | ||
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow() | ||
Assert.assertEquals(expected, actual) | ||
} | ||
|
||
@Test | ||
fun `If the user is logged in the Jetpack app the migration flow should not be shown`() { | ||
whenever(accountStore.hasAccessToken()).thenReturn(true) | ||
val expected = false | ||
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow() | ||
Assert.assertEquals(expected, actual) | ||
} | ||
|
||
@Test | ||
fun `When the WordPress app is not installed the Jetpack app the migration flow should not be shown`() { | ||
whenever(appStatus.isAppInstalled(any())).thenReturn(false) | ||
val expected = false | ||
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow() | ||
Assert.assertEquals(expected, actual) | ||
} | ||
|
||
@Test | ||
fun `When the WordPress app is not compatible the Jetpack app the migration flow should not be shown`() { | ||
whenever(wordPressPublicData.nonSemanticPackageVersion()).thenReturn("21.2") | ||
val expected = false | ||
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow() | ||
Assert.assertEquals(expected, actual) | ||
} | ||
|
||
@Test | ||
fun `When the WordPress app version is null the Jetpack app the migration flow should not be shown`() { | ||
whenever(wordPressPublicData.nonSemanticPackageVersion()).thenReturn(null) | ||
val expected = false | ||
val actual = jetpackAppMigrationFlowUtils.shouldShowMigrationFlow() | ||
Assert.assertEquals(expected, actual) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice tests 👍