Skip to content

Commit

Permalink
Merge pull request #412 from Ecwid/ECWID-138834
Browse files Browse the repository at this point in the history
ECWID-138834 added parameters for searching orders
  • Loading branch information
winrokru authored Jun 11, 2024
2 parents 5f79b94 + 211897a commit d033232
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data class OrdersSearchRequest(
val customer: String? = null,
val customerId: Int? = null,
val email: String? = null,
val customerIdOrEmail: Boolean? = null,
val paymentMethod: String? = null,
val shippingMethod: String? = null,
val paymentStatus: List<OrderPaymentStatus>? = null,
Expand Down Expand Up @@ -60,6 +61,7 @@ data class OrdersSearchRequest(
request.customer?.let { put("customer", it) }
request.customerId?.let { put("customerId", it.toString()) }
request.email?.let { put("email", it) }
request.customerIdOrEmail?.let { put("customerIdOrEmail", it.toString()) }
request.paymentMethod?.let { put("paymentMethod", it) }
request.shippingMethod?.let { put("shippingMethod", it) }
request.paymentStatus?.let { put("paymentStatus", it.joinToString(",")) }
Expand Down
12 changes: 12 additions & 0 deletions src/test/kotlin/com/ecwid/apiclient/v3/entity/CartsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,21 @@ private fun UpdatedOrder.cleanupForComparison(order: UpdatedOrder): UpdatedOrder
option.copy(
valueTranslated = order.items?.get(index)?.selectedOptions?.get(optIndex)?.valueTranslated
)
},
discounts = order.items?.get(index)?.discounts?.mapIndexed { discountIndex, discount ->
discount.copy(
discountInfo = order.items?.get(index)?.discounts?.get(discountIndex)?.discountInfo?.copy(
appliesToItems = null
)
)
}
)
},
customerFiscalCode = null, // ApiOrder has empty string instead of null
discountInfo = order.discountInfo?.map {
it.copy(
appliesToItems = null
)
}
)
}
37 changes: 28 additions & 9 deletions src/test/kotlin/com/ecwid/apiclient/v3/entity/CustomersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,34 @@ class CustomersTest : BaseEntityTest() {
val customerCreateResult2 = apiClient.createCustomer(customerCreateRequest2)
assertTrue(customerCreateResult2.id > 0)

// Creating order for one of those customers
val orderCreateRequest = OrderCreateRequest(
newOrder = UpdatedOrder(
email = customerCreateRequest2.newCustomer.email
email = customerCreateRequest1.newCustomer.email,
total = 5.0
)
)
val orderCreateResult = apiClient.createOrder(orderCreateRequest)
assertTrue(orderCreateResult.id > 0)

val orderCreateRequest2 = OrderCreateRequest(
newOrder = UpdatedOrder(
email = customerCreateRequest2.newCustomer.email,
total = 5.0
)
)
val orderCreateResult2 = apiClient.createOrder(orderCreateRequest2)
assertTrue(orderCreateResult2.id > 0)


val orderCreateRequest3 = OrderCreateRequest(
newOrder = UpdatedOrder(
email = customerCreateRequest2.newCustomer.email,
total = 5.0
)
)
val orderCreateResult3 = apiClient.createOrder(orderCreateRequest3)
assertTrue(orderCreateResult3.id > 0)

// Trying to search using different sorts

assertCustomersSortBySearch(customerCreateResult1.id, SortOrder.NAME_ASC)
Expand All @@ -293,15 +312,15 @@ class CustomersTest : BaseEntityTest() {

assertCustomersSortBySearch(customerCreateResult1.id, SortOrder.UPDATED_DATE_ASC)
assertCustomersSortBySearch(customerCreateResult2.id, SortOrder.UPDATED_DATE_DESC)
// TODO раскомментировать после выхода ECWID-115142
// assertCustomersSortBySearch(customerCreateResult1.id, SortOrder.SALES_VALUE_ASC)
// assertCustomersSortBySearch(customerCreateResult2.id, SortOrder.SALES_VALUE_DESC)

// assertCustomersSortBySearch(customerCreateResult1.id, SortOrder.FIRST_ORDER_DATE_ASC)
// assertCustomersSortBySearch(customerCreateResult2.id, SortOrder.FIRST_ORDER_DATE_DESC)
assertCustomersSortBySearch(customerCreateResult1.id, SortOrder.SALES_VALUE_ASC)
assertCustomersSortBySearch(customerCreateResult2.id, SortOrder.SALES_VALUE_DESC)

assertCustomersSortBySearch(customerCreateResult1.id, SortOrder.FIRST_ORDER_DATE_ASC)
assertCustomersSortBySearch(customerCreateResult2.id, SortOrder.FIRST_ORDER_DATE_DESC)

// assertCustomersSortBySearch(customerCreateResult1.id, SortOrder.LAST_ORDER_DATE_ASC)
// assertCustomersSortBySearch(customerCreateResult2.id, SortOrder.LAST_ORDER_DATE_DESC)
assertCustomersSortBySearch(customerCreateResult1.id, SortOrder.LAST_ORDER_DATE_ASC)
assertCustomersSortBySearch(customerCreateResult2.id, SortOrder.LAST_ORDER_DATE_DESC)
}

@Test
Expand Down
19 changes: 18 additions & 1 deletion src/test/kotlin/com/ecwid/apiclient/v3/entity/OrdersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ private fun UpdatedOrder.cleanupForComparison(order: UpdatedOrder): UpdatedOrder
item.cleanupForComparison(requestItem)
},
customerFiscalCode = null, // ApiOrder has empty string instead of null
discountInfo = order.discountInfo?.map {
it.copy(
appliesToItems = null
)
}
)
}

Expand All @@ -445,7 +450,11 @@ private fun UpdatedOrder.OrderItem.cleanupForComparison(orderItem: UpdatedOrder.
selectedOptions = selectedOptions?.mapIndexed { index, option ->
val requestOption = orderItem?.selectedOptions?.get(index)
option.cleanupForComparison(requestOption)
}
},
discounts = discounts?.mapIndexed { index, discount ->
val requestDiscount = orderItem?.discounts?.get(index)
discount.cleanupForComparison(requestDiscount)
},
)
}

Expand All @@ -458,3 +467,11 @@ private fun UpdatedOrder.OrderItemSelectedOption.cleanupForComparison(orderItemS
}
)
}

private fun UpdatedOrder.OrderItemDiscounts.cleanupForComparison(orderItemSelectedDiscount: UpdatedOrder.OrderItemDiscounts?): UpdatedOrder.OrderItemDiscounts {
return copy(
discountInfo = orderItemSelectedDiscount?.discountInfo?.copy(
appliesToItems = null
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ val ordersSearchRequestRequestNullablePropertyRules: List<NullablePropertyRule<*
AllowNullable(OrdersSearchRequest::customer),
AllowNullable(OrdersSearchRequest::customerId),
AllowNullable(OrdersSearchRequest::email),
AllowNullable(OrdersSearchRequest::customerIdOrEmail),
AllowNullable(OrdersSearchRequest::fulfillmentStatus),
AllowNullable(OrdersSearchRequest::ids),
AllowNullable(OrdersSearchRequest::keywords),
Expand Down

0 comments on commit d033232

Please sign in to comment.