11package com.woocommerce.android.ui.woopos.common.data.searchbyidentifier
22
3- import com.woocommerce.android.model.Product
4- import com.woocommerce.android.model.toAppModel
5- import com.woocommerce.android.ui.products.ProductBackorderStatus
6- import com.woocommerce.android.ui.products.ProductStatus
7- import com.woocommerce.android.ui.products.ProductStockStatus
8- import com.woocommerce.android.ui.products.ProductTaxStatus
9- import com.woocommerce.android.ui.products.ProductTestUtils
10- import com.woocommerce.android.ui.products.ProductType
11- import com.woocommerce.android.ui.products.settings.ProductCatalogVisibility
123import com.woocommerce.android.ui.woopos.common.data.WooPosProductsCache
134import com.woocommerce.android.ui.woopos.common.data.WooPosVariation
5+ import com.woocommerce.android.ui.woopos.common.data.models.WooPosProductModel
146import com.woocommerce.android.ui.woopos.home.items.variations.WooPosVariationsLRUCache
7+ import com.woocommerce.android.ui.woopos.util.generateWooPosProduct
158import kotlinx.coroutines.test.runTest
169import org.junit.Assert.assertEquals
1710import org.junit.Before
@@ -20,14 +13,13 @@ import org.mockito.kotlin.any
2013import org.mockito.kotlin.mock
2114import org.mockito.kotlin.whenever
2215import java.math.BigDecimal
23- import java.util.Date
2416import kotlin.test.assertTrue
2517
2618class WooPosSearchByIdentifierLocalTest {
2719
2820 private lateinit var sut: WooPosSearchByIdentifierLocal
2921 private val productsCache: WooPosProductsCache = mock {
30- onBlocking { getProductById(any()) }.thenReturn(ProductTestUtils .generateWCProductModel().toAppModel ())
22+ onBlocking { getProductById(any()) }.thenReturn(generateWooPosProduct ())
3123 }
3224 private val variationsCache: WooPosVariationsLRUCache = mock()
3325
@@ -40,7 +32,7 @@ class WooPosSearchByIdentifierLocalTest {
4032 fun `given product with matching global unique id, when search called, then return product` () = runTest {
4133 // GIVEN
4234 val identifier = " 1234567890123"
43- val product = createProduct (globalUniqueId = identifier)
35+ val product = generateWooPosProduct (globalUniqueId = identifier)
4436 whenever(productsCache.getAll()).thenReturn(listOf (product))
4537 whenever(variationsCache.getAll()).thenReturn(emptyList())
4638
@@ -69,7 +61,7 @@ class WooPosSearchByIdentifierLocalTest {
6961 fun `given product with lowercase global unique id, when search with uppercase, then return product` () = runTest {
7062 // GIVEN
7163 val identifier = " ABC123"
72- val product = createProduct (globalUniqueId = " abc123" )
64+ val product = generateWooPosProduct (globalUniqueId = " abc123" )
7365 whenever(productsCache.getAll()).thenReturn(listOf (product))
7466 whenever(variationsCache.getAll()).thenReturn(emptyList())
7567
@@ -86,7 +78,8 @@ class WooPosSearchByIdentifierLocalTest {
8678 val identifier = " VAR123456"
8779 val productId = 1L
8880 val variationId = 10L
89- val product = createProduct(remoteId = productId).copy(type = ProductType .VARIABLE .value)
81+ val product =
82+ generateWooPosProduct(productId = productId, productType = WooPosProductModel .WooPosProductType .VARIABLE )
9083 val variation = WooPosVariation (
9184 remoteVariationId = variationId,
9285 remoteProductId = productId,
@@ -115,7 +108,8 @@ class WooPosSearchByIdentifierLocalTest {
115108 // GIVEN
116109 val identifier = " MATCH-VAR"
117110 val productId = 1L
118- val product = createProduct(remoteId = productId).copy(type = ProductType .VARIABLE .value)
111+ val product =
112+ generateWooPosProduct(productId = productId, productType = WooPosProductModel .WooPosProductType .VARIABLE )
119113 val variation1 = WooPosVariation (
120114 remoteVariationId = 10L ,
121115 remoteProductId = productId,
@@ -154,7 +148,8 @@ class WooPosSearchByIdentifierLocalTest {
154148 // GIVEN
155149 val identifier = " VAR-UPPER"
156150 val productId = 1L
157- val product = createProduct(remoteId = productId).copy(type = ProductType .VARIABLE .value)
151+ val product =
152+ generateWooPosProduct(productId = productId, productType = WooPosProductModel .WooPosProductType .VARIABLE )
158153 val variation = WooPosVariation (
159154 remoteVariationId = 10L ,
160155 remoteProductId = productId,
@@ -205,80 +200,4 @@ class WooPosSearchByIdentifierLocalTest {
205200 assertTrue(result is WooPosSearchByIdentifierResult .Failure )
206201 assertEquals(WooPosSearchByIdentifierResult .Error .NotFound , result.error)
207202 }
208-
209- @Suppress(" LongMethod" )
210- private fun createProduct (
211- remoteId : Long = 1,
212- name : String = "Test Product ",
213- sku : String = "",
214- globalUniqueId : String = ""
215- ) = Product (
216- remoteId = remoteId,
217- parentId = 0 ,
218- name = name,
219- description = " " ,
220- shortDescription = " " ,
221- slug = " " ,
222- type = ProductType .SIMPLE .value,
223- status = ProductStatus .PUBLISH ,
224- catalogVisibility = ProductCatalogVisibility .VISIBLE ,
225- isFeatured = false ,
226- stockStatus = ProductStockStatus .InStock ,
227- backorderStatus = ProductBackorderStatus .No ,
228- dateCreated = Date (),
229- firstImageUrl = null ,
230- totalSales = 0 ,
231- reviewsAllowed = true ,
232- isVirtual = false ,
233- ratingCount = 0 ,
234- averageRating = 0f ,
235- permalink = " " ,
236- externalUrl = " " ,
237- buttonText = " " ,
238- price = BigDecimal .TEN ,
239- salePrice = null ,
240- regularPrice = BigDecimal .TEN ,
241- taxClass = Product .TAX_CLASS_DEFAULT ,
242- isStockManaged = false ,
243- stockQuantity = 0.0 ,
244- sku = sku,
245- globalUniqueId = globalUniqueId,
246- shippingClass = " " ,
247- shippingClassId = 0 ,
248- isDownloadable = false ,
249- downloads = emptyList(),
250- downloadLimit = 0 ,
251- downloadExpiry = 0 ,
252- purchaseNote = " " ,
253- numVariations = 0 ,
254- images = emptyList(),
255- attributes = emptyList(),
256- saleEndDateGmt = null ,
257- saleStartDateGmt = null ,
258- isSoldIndividually = false ,
259- taxStatus = ProductTaxStatus .Taxable ,
260- isSaleScheduled = false ,
261- isPurchasable = true ,
262- menuOrder = 0 ,
263- categories = emptyList(),
264- tags = emptyList(),
265- groupedProductIds = emptyList(),
266- crossSellProductIds = emptyList(),
267- upsellProductIds = emptyList(),
268- variationIds = emptyList(),
269- length = 0f ,
270- width = 0f ,
271- height = 0f ,
272- weight = 0f ,
273- isSampleProduct = false ,
274- specialStockStatus = null ,
275- isConfigurable = false ,
276- minAllowedQuantity = null ,
277- maxAllowedQuantity = null ,
278- bundleMinSize = null ,
279- bundleMaxSize = null ,
280- groupOfQuantity = null ,
281- combineVariationQuantities = null ,
282- password = null
283- )
284203}
0 commit comments