From 7ad1464bfcef9026318ad4e490d6e4e956087ba5 Mon Sep 17 00:00:00 2001 From: "andrey.galochkin" Date: Thu, 21 Mar 2024 23:57:02 +0400 Subject: [PATCH 1/6] ECWID-136994 Add search parameter to the customer group endpoint - Added new parameters to the getCustomerGroups request model --- .../customergroup/request/CustomerGroupsSearchRequest.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/customergroup/request/CustomerGroupsSearchRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/customergroup/request/CustomerGroupsSearchRequest.kt index 61d54bcd0..3e8950b07 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/customergroup/request/CustomerGroupsSearchRequest.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/customergroup/request/CustomerGroupsSearchRequest.kt @@ -7,6 +7,8 @@ import com.ecwid.apiclient.v3.responsefields.ResponseFields data class CustomerGroupsSearchRequest( val offset: Int = 0, val limit: Int = 100, + val keyword: String? = null, + val customerGroupIds: List? = null, val responseFields: ResponseFields = ResponseFields.All, ) : ApiRequest { override fun toRequestInfo() = RequestInfo.createGetRequest( @@ -22,6 +24,12 @@ data class CustomerGroupsSearchRequest( return mutableMapOf().apply { put("offset", request.offset.toString()) put("limit", request.limit.toString()) + if (!request.keyword.isNullOrBlank()) { + put("keyword", request.keyword.toString()) + } + if (!request.customerGroupIds.isNullOrEmpty()) { + put("customerGroupIds", request.customerGroupIds.joinToString(",")) + } }.toMap() } } From c88931b801a36bd85dc0af9dafef6ed5e6b6052c Mon Sep 17 00:00:00 2001 From: "andrey.galochkin" Date: Thu, 21 Mar 2024 23:57:02 +0400 Subject: [PATCH 2/6] added new parameters to the getCustomerGroups request model --- .../customergroup/request/CustomerGroupsSearchRequest.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/customergroup/request/CustomerGroupsSearchRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/customergroup/request/CustomerGroupsSearchRequest.kt index 61d54bcd0..3e8950b07 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/customergroup/request/CustomerGroupsSearchRequest.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/customergroup/request/CustomerGroupsSearchRequest.kt @@ -7,6 +7,8 @@ import com.ecwid.apiclient.v3.responsefields.ResponseFields data class CustomerGroupsSearchRequest( val offset: Int = 0, val limit: Int = 100, + val keyword: String? = null, + val customerGroupIds: List? = null, val responseFields: ResponseFields = ResponseFields.All, ) : ApiRequest { override fun toRequestInfo() = RequestInfo.createGetRequest( @@ -22,6 +24,12 @@ data class CustomerGroupsSearchRequest( return mutableMapOf().apply { put("offset", request.offset.toString()) put("limit", request.limit.toString()) + if (!request.keyword.isNullOrBlank()) { + put("keyword", request.keyword.toString()) + } + if (!request.customerGroupIds.isNullOrEmpty()) { + put("customerGroupIds", request.customerGroupIds.joinToString(",")) + } }.toMap() } } From aaa83f753d64ff1cef9b066b9f1653f04d4d6d57 Mon Sep 17 00:00:00 2001 From: "andrey.galochkin" Date: Fri, 22 Mar 2024 15:17:38 +0400 Subject: [PATCH 3/6] make new parameters Nullable for the tests --- .../com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt index a67c40c35..2b2d1ad38 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/rule/NullablePropertyRules.kt @@ -6,6 +6,7 @@ import com.ecwid.apiclient.v3.dto.batch.result.GetEscapedBatchResult import com.ecwid.apiclient.v3.dto.batch.result.GetTypedBatchResult import com.ecwid.apiclient.v3.dto.cart.result.CartUpdateResult import com.ecwid.apiclient.v3.dto.cart.result.ConvertCartToOrderResult +import com.ecwid.apiclient.v3.dto.customergroup.request.CustomerGroupsSearchRequest import com.ecwid.apiclient.v3.dto.instantsite.redirects.request.InstantSiteRedirectsGetForExactPathRequest import com.ecwid.apiclient.v3.dto.instantsite.redirects.request.InstantSiteRedirectsSearchRequest import com.ecwid.apiclient.v3.dto.order.result.DeletedOrder @@ -132,6 +133,9 @@ val otherNullablePropertyRules: List> = listOf( AllowNullable(InstantSiteRedirectsGetForExactPathRequest::exactPath), AllowNullable(UpdatedProductReviewStatus::status), + + AllowNullable(CustomerGroupsSearchRequest::keyword), + AllowNullable(CustomerGroupsSearchRequest::customerGroupIds), ) val nullablePropertyRules: List> = listOf( From bc325fe0500d28ffed734be85f1e16606957ab9b Mon Sep 17 00:00:00 2001 From: "andrey.galochkin" Date: Fri, 22 Mar 2024 15:59:10 +0400 Subject: [PATCH 4/6] removed unnecessary convert to string --- .../v3/dto/customergroup/request/CustomerGroupsSearchRequest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/ecwid/apiclient/v3/dto/customergroup/request/CustomerGroupsSearchRequest.kt b/src/main/kotlin/com/ecwid/apiclient/v3/dto/customergroup/request/CustomerGroupsSearchRequest.kt index 3e8950b07..e968cf3f5 100644 --- a/src/main/kotlin/com/ecwid/apiclient/v3/dto/customergroup/request/CustomerGroupsSearchRequest.kt +++ b/src/main/kotlin/com/ecwid/apiclient/v3/dto/customergroup/request/CustomerGroupsSearchRequest.kt @@ -25,7 +25,7 @@ data class CustomerGroupsSearchRequest( put("offset", request.offset.toString()) put("limit", request.limit.toString()) if (!request.keyword.isNullOrBlank()) { - put("keyword", request.keyword.toString()) + put("keyword", request.keyword) } if (!request.customerGroupIds.isNullOrEmpty()) { put("customerGroupIds", request.customerGroupIds.joinToString(",")) From c7a8076165f76b0604764ecb2e40853d2e574002 Mon Sep 17 00:00:00 2001 From: "andrey.galochkin" Date: Tue, 26 Mar 2024 15:40:32 +0400 Subject: [PATCH 5/6] Fixed old and implemented new search customer group paging tests --- .../apiclient/v3/entity/CustomerGroupsTest.kt | 56 ++++++++++++++++--- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/entity/CustomerGroupsTest.kt b/src/test/kotlin/com/ecwid/apiclient/v3/entity/CustomerGroupsTest.kt index f19426e18..fe7b096b1 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/entity/CustomerGroupsTest.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/entity/CustomerGroupsTest.kt @@ -9,6 +9,9 @@ import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +const val TEST_SEARCH_PHRASE = "Test" +const val TEST_CUSTOMER_GROUP = "Customer group" + class CustomerGroupsTest : BaseEntityTest() { @BeforeEach @@ -61,10 +64,11 @@ class CustomerGroupsTest : BaseEntityTest() { @Test fun testSearchPaging() { - // Create three customer groups additionally to always existing “General” group - repeat(3) { + // Create 6 customer groups to test paging + val customerGroups = generateSearchTestCustomerGroups() + repeat(customerGroups.size) { val customerGroupCreateRequest = CustomerGroupCreateRequest( - newCustomerGroup = generateTestCustomerGroup() + newCustomerGroup = customerGroups[it] ) val customerGroupCreateResult = apiClient.createCustomerGroup(customerGroupCreateRequest) assertTrue(customerGroupCreateResult.id > 0) @@ -73,19 +77,53 @@ class CustomerGroupsTest : BaseEntityTest() { // Trying to request first page val customerGroupsSearchRequest1 = CustomerGroupsSearchRequest(offset = 0, limit = 2) val customerGroupsSearchResult1 = apiClient.searchCustomerGroups(customerGroupsSearchRequest1) - assertEquals(2 + 1, customerGroupsSearchResult1.count) // “General” group exists is on every page - assertEquals(3, customerGroupsSearchResult1.total) + assertEquals(2, customerGroupsSearchResult1.count) // “General” group exists only of first page + assertEquals(7, customerGroupsSearchResult1.total) // Trying to request second and the last page - val customerGroupsSearchRequest2 = CustomerGroupsSearchRequest(offset = 2, limit = 2) + val customerGroupsSearchRequest2 = CustomerGroupsSearchRequest(offset = 6, limit = 2) val customerGroupsSearchResult2 = apiClient.searchCustomerGroups(customerGroupsSearchRequest2) - assertEquals(1 + 1, customerGroupsSearchResult2.count) // “General” group exists is on every page - assertEquals(3, customerGroupsSearchResult2.total) + assertEquals(1, customerGroupsSearchResult2.count) // “General” group exists only of first page + assertEquals(7, customerGroupsSearchResult2.total) + + // test by keyword "Customer group" + val customerGroupsSearchRequest3 = CustomerGroupsSearchRequest( + keyword = TEST_CUSTOMER_GROUP, + ) + val customerGroupsSearchResult3 = apiClient.searchCustomerGroups(customerGroupsSearchRequest3) + assertEquals(true, customerGroupsSearchResult3.items.all { it.name.contains(TEST_CUSTOMER_GROUP) }) + + // test by keyword "Test" + val customerGroupsSearchRequest4 = CustomerGroupsSearchRequest( + keyword = TEST_SEARCH_PHRASE, + ) + val customerGroupsSearchResult4 = apiClient.searchCustomerGroups(customerGroupsSearchRequest4) + assertEquals(true, customerGroupsSearchResult4.items.all { it.name.contains(TEST_SEARCH_PHRASE) }) + + val testGroupIds = customerGroupsSearchResult4.items.map { it.id } + + // test by customerGroupIds + val customerGroupsSearchRequest5 = CustomerGroupsSearchRequest( + customerGroupIds = testGroupIds, + ) + val customerGroupsSearchResult5 = apiClient.searchCustomerGroups(customerGroupsSearchRequest5) + assertEquals(testGroupIds.size, customerGroupsSearchResult5.total) + assertEquals(testGroupIds, customerGroupsSearchResult5.items.map { it.id }) + } } private fun generateTestCustomerGroup(): UpdatedCustomerGroup { return UpdatedCustomerGroup( - name = "Customer group " + randomAlphanumeric(8) + name = "$$TEST_CUSTOMER_GROUP " + randomAlphanumeric(8) ) } + +private fun generateSearchTestCustomerGroups(): List { + val result = mutableListOf() + repeat(3) { + result.add(UpdatedCustomerGroup("$TEST_CUSTOMER_GROUP $it")) + result.add(UpdatedCustomerGroup("$TEST_SEARCH_PHRASE $it")) + } + return result +} From fa1ed65a1a731d592cff5612d3c6f9ed888d04d9 Mon Sep 17 00:00:00 2001 From: "andrey.galochkin" Date: Mon, 8 Apr 2024 15:56:05 +0400 Subject: [PATCH 6/6] Corrected a mistake in the text --- .../kotlin/com/ecwid/apiclient/v3/entity/CustomerGroupsTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/com/ecwid/apiclient/v3/entity/CustomerGroupsTest.kt b/src/test/kotlin/com/ecwid/apiclient/v3/entity/CustomerGroupsTest.kt index fe7b096b1..a4145afaa 100644 --- a/src/test/kotlin/com/ecwid/apiclient/v3/entity/CustomerGroupsTest.kt +++ b/src/test/kotlin/com/ecwid/apiclient/v3/entity/CustomerGroupsTest.kt @@ -115,7 +115,7 @@ class CustomerGroupsTest : BaseEntityTest() { private fun generateTestCustomerGroup(): UpdatedCustomerGroup { return UpdatedCustomerGroup( - name = "$$TEST_CUSTOMER_GROUP " + randomAlphanumeric(8) + name = "$TEST_CUSTOMER_GROUP " + randomAlphanumeric(8) ) }