Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.woocommerce.android.ciab

enum class CIABAffectedFeature {
Blaze,
Payments,
WooShippingSplitShipments,
GroupedProducts,
VariableProducts,
GiftCardEditing,
ProductsStockDashboardCard
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.woocommerce.android.ciab

import androidx.annotation.VisibleForTesting
import com.woocommerce.android.tools.SelectedSite
import javax.inject.Inject

class CIABSiteGateKeeper @Inject constructor(private val selectedSite: SelectedSite) {
fun isFeatureSupported(
@Suppress("unused")
feature: CIABAffectedFeature
): Boolean {
// For now, all affected features are unsupported in CIAB.
// If there are exceptions in the future, we can handle them here.
return !isCurrentSiteCIAB()
}

fun isFeatureUnsupported(feature: CIABAffectedFeature): Boolean {
return !isFeatureSupported(feature)
}

private fun isCurrentSiteCIAB(): Boolean {
val site = selectedSite.getOrNull() ?: return false
return site.isGardenSite && site.gardenName == CIAB_GARDEN_NAME
}

companion object Companion {
@VisibleForTesting
const val CIAB_GARDEN_NAME = "commerce"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.woocommerce.android.ciab

import com.woocommerce.android.tools.SelectedSite
import com.woocommerce.android.viewmodel.BaseUnitTest
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.mockito.Mockito.mock
import org.mockito.kotlin.given
import org.wordpress.android.fluxc.model.SiteModel

@OptIn(ExperimentalCoroutinesApi::class)
class CIABSiteGateKeeperTest : BaseUnitTest() {
private val selectedSite: SelectedSite = mock()
private val ciabSiteGateKeeper = CIABSiteGateKeeper(selectedSite)

@Test
fun `given current site is CIAB, when checking feature support, then feature is unsupported`() {
val site = createSite(isCIAB = true)
given(selectedSite.getOrNull()).willReturn(site)

CIABAffectedFeature.entries.forEach {
assertFalse(ciabSiteGateKeeper.isFeatureSupported(it))
}
}

@Test
fun `given current site is not CIAB, when checking feature support, then feature is supported`() {
val site = createSite(isCIAB = false)
given(selectedSite.getOrNull()).willReturn(site)

CIABAffectedFeature.entries.forEach {
assertTrue(ciabSiteGateKeeper.isFeatureSupported(it))
}
}

private fun createSite(isCIAB: Boolean): SiteModel {
return SiteModel().apply {
setIsGardenSite(isCIAB)
this.gardenName = if (isCIAB) CIABSiteGateKeeper.CIAB_GARDEN_NAME else null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ public class SiteModel extends Payload<BaseNetworkError> implements Identifiable
private Boolean mWasEcommerceTrial;
@Column
private Boolean mIsSingleUserSite;
@Column
private boolean mIsGardenSite;
@Column
@Nullable
private String mGardenName;
@Column
@Nullable
private String mGardenPartner;

@Override
public int getId() {
Expand Down Expand Up @@ -1137,6 +1145,32 @@ public void setIsSingleUserSite(Boolean isSingleUserSite) {
mIsSingleUserSite = isSingleUserSite;
}

public boolean isGardenSite() {
return mIsGardenSite;
}

public void setIsGardenSite(boolean mIsGardenSite) {
this.mIsGardenSite = mIsGardenSite;
}

@Nullable
public String getGardenName() {
return mGardenName;
}

public void setGardenName(@Nullable String mGardenName) {
this.mGardenName = mGardenName;
}

@Nullable
public String getGardenPartner() {
return mGardenPartner;
}

public void setGardenPartner(@Nullable String mGardenPartner) {
this.mGardenPartner = mGardenPartner;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof SiteModel)) return false;
Expand Down Expand Up @@ -1236,7 +1270,10 @@ public boolean equals(Object o) {
Objects.equals(mCanBlaze, siteModel.mCanBlaze) &&
Objects.equals(mPlanActiveFeatures, siteModel.mPlanActiveFeatures) &&
Objects.equals(mWasEcommerceTrial, siteModel.mWasEcommerceTrial) &&
Objects.equals(mIsSingleUserSite, siteModel.mIsSingleUserSite);
Objects.equals(mIsSingleUserSite, siteModel.mIsSingleUserSite) &&
mIsGardenSite == siteModel.mIsGardenSite &&
Objects.equals(mGardenName, siteModel.mGardenName) &&
Objects.equals(mGardenPartner, siteModel.mGardenPartner);
}

@Override
Expand Down Expand Up @@ -1336,6 +1373,9 @@ public int hashCode() {
mCanBlaze,
mPlanActiveFeatures,
mWasEcommerceTrial,
mIsSingleUserSite);
mIsSingleUserSite,
mIsGardenSite,
mGardenName,
mGardenPartner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,11 @@ class SiteRestClient @Inject constructor(
site.planActiveFeatures = (from.plan?.features?.active?.joinToString(",")).orEmpty()
site.wasEcommerceTrial = from.was_ecommerce_trial
site.setIsSingleUserSite(from.single_user_site)

site.setIsGardenSite(from.is_garden)
site.gardenName = from.garden_name
site.gardenPartner = from.garden_partner

return site
}

Expand Down Expand Up @@ -1186,7 +1191,7 @@ class SiteRestClient @Inject constructor(
@VisibleForTesting
const val SITE_FIELDS = "ID,URL,name,description,jetpack,jetpack_connection,visible,is_private," +
"options,plan,capabilities,quota,icon,meta,zendesk_site_meta,organization_id," +
"was_ecommerce_trial,single_user_site,jetpack_modules"
"was_ecommerce_trial,single_user_site,jetpack_modules,is_garden,garden_name,garden_partner"
private const val ROOT_ENDPOINT_FIELDS = "name,description,gmt_offset,namespaces,authentication"
private const val WOO_API_NAMESPACE_PREFIX = "wc/"
private const val FIELDS = "fields"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,7 @@
public boolean was_ecommerce_trial;
public boolean single_user_site;
public List<String> jetpack_modules;
public boolean is_garden;
public String garden_name;

Check notice

Code scanning / Android Lint

Nullable/NonNull annotation missing on field Note

Missing null annotation
public String garden_partner;

Check notice

Code scanning / Android Lint

Nullable/NonNull annotation missing on field Note

Missing null annotation
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ open class WellSqlConfig : DefaultWellConfig {
annotation class AddOn

override fun getDbVersion(): Int {
return 230
return 231
}

override fun getDbName(): String {
Expand Down Expand Up @@ -2246,6 +2246,12 @@ open class WellSqlConfig : DefaultWellConfig {
229 -> migrateAddOn(ADDON_WOOCOMMERCE, version) {
db.execSQL("DROP TABLE IF EXISTS WCNewVisitorStatsModel")
}

230 -> migrate(version) {
db.execSQL("ALTER TABLE SiteModel ADD IS_GARDEN_SITE BOOLEAN NOT NULL DEFAULT 0")
db.execSQL("ALTER TABLE SiteModel ADD GARDEN_NAME TEXT")
db.execSQL("ALTER TABLE SiteModel ADD GARDEN_PARTNER TEXT")
}
}
}
db.setTransactionSuccessful()
Expand Down