Skip to content

Commit

Permalink
Merge pull request #14644 from wordpress-mobile/issue/14620-magic-lin…
Browse files Browse the repository at this point in the history
…k-scheme

Jetpack App (Basics): Update magic link scheme
  • Loading branch information
ParaskP7 authored May 14, 2021
2 parents 3c54ec4 + c0255b1 commit a027326
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 8 deletions.
6 changes: 6 additions & 0 deletions WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ android {
buildConfigField "boolean", "IS_JETPACK_APP", "false"
buildConfigField "String", "TRACKS_EVENT_PREFIX", '"wpandroid_"'
buildConfigField "String", "PUSH_NOTIFICATIONS_APP_KEY", '"org.wordpress.android"'

manifestPlaceholders = [magicLinkScheme:"wordpress"]
}

// Gutenberg's dependency - react-native-video is using
Expand All @@ -100,6 +102,8 @@ android {
buildConfigField "boolean", "IS_JETPACK_APP", "false"
buildConfigField "String", "TRACKS_EVENT_PREFIX", '"wpandroid_"'
buildConfigField "String", "PUSH_NOTIFICATIONS_APP_KEY", '"org.wordpress.android"'

manifestPlaceholders = [magicLinkScheme:"wordpress"]
}

jetpack {
Expand All @@ -108,6 +112,8 @@ android {
buildConfigField "boolean", "IS_JETPACK_APP", "true"
buildConfigField "String", "TRACKS_EVENT_PREFIX", '"jpandroid_"'
buildConfigField "String", "PUSH_NOTIFICATIONS_APP_KEY", '"com.jetpack.android"'

manifestPlaceholders = [magicLinkScheme:"jetpack"]
}

vanilla { // used for release and beta
Expand Down
3 changes: 3 additions & 0 deletions WordPress/src/jetpack/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<string name="app_tagline">Site security and performance from your pocket</string>
<string name="continue_with_wpcom_no_signup">Log in with WordPress.com</string>

<!-- Login Magic Link -->
<string name="login_magic_links_sent_label">Check your email on this device and tap the link in the email you received from Jetpack.com.</string>

<!-- Contact us -->
<!--Note: Support ticket subject, only visible to the end users of the Zendesk support portal, doesn't need a translation -->
<string name="support_ticket_subject" translatable="false">Jetpack for Android Support</string>
Expand Down
2 changes: 1 addition & 1 deletion WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="magic-login"
android:scheme="wordpress" />
android:scheme="${magicLinkScheme}" />
</intent-filter>
</activity>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ private void showEmailPasswordScreen(String email, boolean verifyEmail, boolean

private void showMagicLinkRequestScreen(String email, boolean verifyEmail, boolean allowPassword,
boolean forceRequestAtStart) {
AuthEmailPayloadScheme scheme = AuthEmailPayloadScheme.WORDPRESS;
AuthEmailPayloadScheme scheme = mViewModel.getMagicLinkScheme();
String jetpackConnectionSource = mJetpackConnectSource != null ? mJetpackConnectSource.toString() : null;
LoginMagicLinkRequestFragment loginMagicLinkRequestFragment = LoginMagicLinkRequestFragment
.newInstance(email, scheme, mIsJetpackConnect, jetpackConnectionSource, verifyEmail, allowPassword,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package org.wordpress.android.ui.accounts
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.ViewModel
import org.wordpress.android.fluxc.store.AccountStore.AuthEmailPayloadScheme
import org.wordpress.android.fluxc.store.SiteStore.ConnectSiteInfoPayload
import org.wordpress.android.ui.accounts.LoginNavigationEvents.ShowNoJetpackSites
import org.wordpress.android.ui.accounts.LoginNavigationEvents.ShowSiteAddressError
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.viewmodel.Event
import javax.inject.Inject
import kotlin.text.RegexOption.IGNORE_CASE

class LoginViewModel @Inject constructor() : ViewModel() {
class LoginViewModel @Inject constructor(private val buildConfigWrapper: BuildConfigWrapper) : ViewModel() {
private val _navigationEvents = MediatorLiveData<Event<LoginNavigationEvents>>()
val navigationEvents: LiveData<Event<LoginNavigationEvents>> = _navigationEvents

Expand All @@ -23,4 +25,10 @@ class LoginViewModel @Inject constructor() : ViewModel() {
fun onHandleNoJetpackSites() {
_navigationEvents.postValue(Event(ShowNoJetpackSites))
}

fun getMagicLinkScheme() = if (buildConfigWrapper.isJetpackApp) {
AuthEmailPayloadScheme.JETPACK
} else {
AuthEmailPayloadScheme.WORDPRESS
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package org.wordpress.android.ui.accounts

import org.assertj.core.api.Assertions
import com.nhaarman.mockitokotlin2.whenever
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
import org.junit.Test
import org.mockito.Mock
import org.wordpress.android.BaseUnitTest
import org.wordpress.android.fluxc.store.AccountStore.AuthEmailPayloadScheme
import org.wordpress.android.fluxc.store.SiteStore.ConnectSiteInfoPayload
import org.wordpress.android.ui.accounts.LoginNavigationEvents.ShowNoJetpackSites
import org.wordpress.android.ui.accounts.LoginNavigationEvents.ShowSiteAddressError
import org.wordpress.android.util.BuildConfigWrapper
import org.wordpress.android.viewmodel.ResourceProvider

class LoginViewModelTest : BaseUnitTest() {
@Mock lateinit var buildConfigWrapper: BuildConfigWrapper
@Mock lateinit var resourceProvider: ResourceProvider
private lateinit var viewModel: LoginViewModel

@Before
fun setUp() {
viewModel = LoginViewModel()
viewModel = LoginViewModel(buildConfigWrapper)
}

@Test
Expand All @@ -25,7 +29,7 @@ class LoginViewModelTest : BaseUnitTest() {

viewModel.onHandleNoJetpackSites()

Assertions.assertThat(navigationEvents.last()).isInstanceOf(ShowNoJetpackSites::class.java)
assertThat(navigationEvents.last()).isInstanceOf(ShowNoJetpackSites::class.java)
}

@Test
Expand All @@ -36,7 +40,25 @@ class LoginViewModelTest : BaseUnitTest() {
val connectSiteInfoPayload = getConnectSiteInfoPayload(url)
viewModel.onHandleSiteAddressError(connectSiteInfoPayload)

Assertions.assertThat(navigationEvents.last()).isInstanceOf(ShowSiteAddressError::class.java)
assertThat(navigationEvents.last()).isInstanceOf(ShowSiteAddressError::class.java)
}

@Test
fun `given jetpack app, when magic link scheme is requested, then jetpack scheme is returned`() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(true)

val scheme = viewModel.getMagicLinkScheme()

assertThat(scheme).isEqualTo(AuthEmailPayloadScheme.JETPACK)
}

@Test
fun `given wordpress app, when magic link scheme is requested, then wordpress scheme is returned`() {
whenever(buildConfigWrapper.isJetpackApp).thenReturn(false)

val scheme = viewModel.getMagicLinkScheme()

assertThat(scheme).isEqualTo(AuthEmailPayloadScheme.WORDPRESS)
}

private fun getConnectSiteInfoPayload(url: String): ConnectSiteInfoPayload =
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ ext {
androidxWorkVersion = "2.4.0"

daggerVersion = '2.29.1'
fluxCVersion = '1.17.0-beta-3'
fluxCVersion = '1.17.0-beta-4'

appCompatVersion = '1.0.2'
coreVersion = '1.3.2'
Expand Down

0 comments on commit a027326

Please sign in to comment.