Skip to content

Commit c7a8076

Browse files
Fixed old and implemented new search customer group paging tests
1 parent bc325fe commit c7a8076

1 file changed

Lines changed: 47 additions & 9 deletions

File tree

src/test/kotlin/com/ecwid/apiclient/v3/entity/CustomerGroupsTest.kt

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import org.junit.jupiter.api.Assertions.assertTrue
99
import org.junit.jupiter.api.BeforeEach
1010
import org.junit.jupiter.api.Test
1111

12+
const val TEST_SEARCH_PHRASE = "Test"
13+
const val TEST_CUSTOMER_GROUP = "Customer group"
14+
1215
class CustomerGroupsTest : BaseEntityTest() {
1316

1417
@BeforeEach
@@ -61,10 +64,11 @@ class CustomerGroupsTest : BaseEntityTest() {
6164

6265
@Test
6366
fun testSearchPaging() {
64-
// Create three customer groups additionally to always existing “General” group
65-
repeat(3) {
67+
// Create 6 customer groups to test paging
68+
val customerGroups = generateSearchTestCustomerGroups()
69+
repeat(customerGroups.size) {
6670
val customerGroupCreateRequest = CustomerGroupCreateRequest(
67-
newCustomerGroup = generateTestCustomerGroup()
71+
newCustomerGroup = customerGroups[it]
6872
)
6973
val customerGroupCreateResult = apiClient.createCustomerGroup(customerGroupCreateRequest)
7074
assertTrue(customerGroupCreateResult.id > 0)
@@ -73,19 +77,53 @@ class CustomerGroupsTest : BaseEntityTest() {
7377
// Trying to request first page
7478
val customerGroupsSearchRequest1 = CustomerGroupsSearchRequest(offset = 0, limit = 2)
7579
val customerGroupsSearchResult1 = apiClient.searchCustomerGroups(customerGroupsSearchRequest1)
76-
assertEquals(2 + 1, customerGroupsSearchResult1.count) // “General” group exists is on every page
77-
assertEquals(3, customerGroupsSearchResult1.total)
80+
assertEquals(2, customerGroupsSearchResult1.count) // “General” group exists only of first page
81+
assertEquals(7, customerGroupsSearchResult1.total)
7882

7983
// Trying to request second and the last page
80-
val customerGroupsSearchRequest2 = CustomerGroupsSearchRequest(offset = 2, limit = 2)
84+
val customerGroupsSearchRequest2 = CustomerGroupsSearchRequest(offset = 6, limit = 2)
8185
val customerGroupsSearchResult2 = apiClient.searchCustomerGroups(customerGroupsSearchRequest2)
82-
assertEquals(1 + 1, customerGroupsSearchResult2.count) // “General” group exists is on every page
83-
assertEquals(3, customerGroupsSearchResult2.total)
86+
assertEquals(1, customerGroupsSearchResult2.count) // “General” group exists only of first page
87+
assertEquals(7, customerGroupsSearchResult2.total)
88+
89+
// test by keyword "Customer group"
90+
val customerGroupsSearchRequest3 = CustomerGroupsSearchRequest(
91+
keyword = TEST_CUSTOMER_GROUP,
92+
)
93+
val customerGroupsSearchResult3 = apiClient.searchCustomerGroups(customerGroupsSearchRequest3)
94+
assertEquals(true, customerGroupsSearchResult3.items.all { it.name.contains(TEST_CUSTOMER_GROUP) })
95+
96+
// test by keyword "Test"
97+
val customerGroupsSearchRequest4 = CustomerGroupsSearchRequest(
98+
keyword = TEST_SEARCH_PHRASE,
99+
)
100+
val customerGroupsSearchResult4 = apiClient.searchCustomerGroups(customerGroupsSearchRequest4)
101+
assertEquals(true, customerGroupsSearchResult4.items.all { it.name.contains(TEST_SEARCH_PHRASE) })
102+
103+
val testGroupIds = customerGroupsSearchResult4.items.map { it.id }
104+
105+
// test by customerGroupIds
106+
val customerGroupsSearchRequest5 = CustomerGroupsSearchRequest(
107+
customerGroupIds = testGroupIds,
108+
)
109+
val customerGroupsSearchResult5 = apiClient.searchCustomerGroups(customerGroupsSearchRequest5)
110+
assertEquals(testGroupIds.size, customerGroupsSearchResult5.total)
111+
assertEquals(testGroupIds, customerGroupsSearchResult5.items.map { it.id })
112+
84113
}
85114
}
86115

87116
private fun generateTestCustomerGroup(): UpdatedCustomerGroup {
88117
return UpdatedCustomerGroup(
89-
name = "Customer group " + randomAlphanumeric(8)
118+
name = "$$TEST_CUSTOMER_GROUP " + randomAlphanumeric(8)
90119
)
91120
}
121+
122+
private fun generateSearchTestCustomerGroups(): List<UpdatedCustomerGroup> {
123+
val result = mutableListOf<UpdatedCustomerGroup>()
124+
repeat(3) {
125+
result.add(UpdatedCustomerGroup("$TEST_CUSTOMER_GROUP $it"))
126+
result.add(UpdatedCustomerGroup("$TEST_SEARCH_PHRASE $it"))
127+
}
128+
return result
129+
}

0 commit comments

Comments
 (0)