Skip to content

Commit 9de01a6

Browse files
committed
Merge branch 'trunk' into issue/6025-add-shipping-line-section
2 parents c0dba92 + 0a44507 commit 9de01a6

File tree

52 files changed

+2201
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2201
-101
lines changed

Networking/Networking/Model/ShippingLine.swift

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ import Codegen
33

44
/// Represents a Shipping Line Entity.
55
///
6-
public struct ShippingLine: Decodable, Equatable, GeneratedFakeable {
6+
public struct ShippingLine: Codable, Equatable, GeneratedFakeable {
77
public let shippingID: Int64
88
public let methodTitle: String
9-
public let methodID: String
9+
10+
/// Shipping Method ID
11+
///
12+
/// Sending a null value to the REST API removes the Shipping Line.
13+
///
14+
public let methodID: String?
15+
1016
public let total: String
1117
public let totalTax: String
1218
public let taxes: [ShippingLineTax]
@@ -15,7 +21,7 @@ public struct ShippingLine: Decodable, Equatable, GeneratedFakeable {
1521
///
1622
public init(shippingID: Int64,
1723
methodTitle: String,
18-
methodID: String,
24+
methodID: String?,
1925
total: String,
2026
totalTax: String,
2127
taxes: [ShippingLineTax]) {
@@ -29,6 +35,21 @@ public struct ShippingLine: Decodable, Equatable, GeneratedFakeable {
2935
}
3036
}
3137

38+
// MARK: Codable
39+
extension ShippingLine {
40+
41+
/// Encodes ShippingLine writable fields.
42+
///
43+
public func encode(to encoder: Encoder) throws {
44+
var container = encoder.container(keyedBy: CodingKeys.self)
45+
46+
try container.encode(shippingID, forKey: .shippingID)
47+
try container.encode(methodTitle, forKey: .methodTitle)
48+
try container.encode(methodID, forKey: .methodID)
49+
try container.encode(total, forKey: .total)
50+
}
51+
}
52+
3253

3354
/// Defines all of the Shipping Line CodingKeys
3455
///

Networking/Networking/Remote/OrdersRemote.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ public class OrdersRemote: Remote {
147147
if let shippingAddress = order.shippingAddress {
148148
params[Order.CodingKeys.shippingAddress.rawValue] = try shippingAddress.toDictionary()
149149
}
150+
case .shippingLines:
151+
params[Order.CodingKeys.shippingLines.rawValue] = try order.shippingLines.compactMap { try $0.toDictionary() }
150152
}
151153
}
152154
}()
@@ -201,6 +203,9 @@ public class OrdersRemote: Remote {
201203
case .fees:
202204
let feesEncoded = try order.fees.map { try $0.toDictionary() }
203205
params[Order.CodingKeys.feeLines.rawValue] = feesEncoded
206+
case .shippingLines:
207+
let shippingEncoded = try order.shippingLines.map { try $0.toDictionary() }
208+
params[Order.CodingKeys.shippingLines.rawValue] = shippingEncoded
204209
}
205210
}
206211
}()
@@ -269,10 +274,13 @@ public extension OrdersRemote {
269274
private static let commonOrderFieldValues = [
270275
"id", "parent_id", "number", "status", "currency", "customer_id", "customer_note", "date_created_gmt", "date_modified_gmt", "date_paid_gmt",
271276
"discount_total", "discount_tax", "shipping_total", "shipping_tax", "total", "total_tax", "payment_method", "payment_method_title",
272-
"billing", "coupon_lines", "shipping_lines", "refunds", "fee_lines", "order_key", "tax_lines"
277+
"billing", "coupon_lines", "shipping_lines", "refunds", "fee_lines", "order_key", "tax_lines", "meta_data"
273278
]
279+
// Use with caution. Any fields in here will be overwritten with empty values by
280+
// `Order+ReadOnlyConvertible.swift: Order.update(with:)` when the list of orders is fetched.
281+
// See p91TBi-7yL-p2 for discussion.
274282
private static let singleOrderExtraFieldValues = [
275-
"line_items", "shipping", "meta_data"
283+
"line_items", "shipping"
276284
]
277285
}
278286

@@ -283,6 +291,7 @@ public extension OrdersRemote {
283291
case shippingAddress
284292
case billingAddress
285293
case fees
294+
case shippingLines
286295
}
287296

288297
/// Order fields supported for create
@@ -293,5 +302,6 @@ public extension OrdersRemote {
293302
case items
294303
case billingAddress
295304
case shippingAddress
305+
case shippingLines
296306
}
297307
}

Networking/NetworkingTests/Remote/OrdersRemoteTests.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,27 @@ final class OrdersRemoteTests: XCTestCase {
211211
wait(for: [expectation], timeout: Constants.expectationTimeout)
212212
}
213213

214+
func test_update_order_properly_encodes_shipping_lines_for_removal_from_order() throws {
215+
// Given
216+
let remote = OrdersRemote(network: network)
217+
let shipping = ShippingLine(shippingID: 333, methodTitle: "Shipping", methodID: nil, total: "1.23", totalTax: "", taxes: [])
218+
let order = Order.fake().copy(shippingLines: [shipping])
219+
220+
// When
221+
remote.updateOrder(from: 123, order: order, fields: [.shippingLines]) { result in }
222+
223+
// Then
224+
let request = try XCTUnwrap(network.requestsForResponseData.last as? JetpackRequest)
225+
let received = try XCTUnwrap(request.parameters["shipping_lines"] as? [[String: AnyHashable]]).first
226+
let expected: [String: AnyHashable] = [
227+
"id": shipping.shippingID,
228+
"method_title": shipping.methodTitle,
229+
"method_id": NSNull(),
230+
"total": shipping.total
231+
]
232+
assertEqual(received, expected)
233+
}
234+
214235

215236
// MARK: - Load Order Notes Tests
216237

@@ -264,6 +285,8 @@ final class OrdersRemoteTests: XCTestCase {
264285
wait(for: [expectation], timeout: Constants.expectationTimeout)
265286
}
266287

288+
// MARK: - Create Order Tests
289+
267290
func test_create_order_properly_encodes_fee_lines() throws {
268291
// Given
269292
let remote = OrdersRemote(network: network)
@@ -376,6 +399,27 @@ final class OrdersRemoteTests: XCTestCase {
376399
]
377400
assertEqual(received2, expected2)
378401
}
402+
403+
func test_create_order_properly_encodes_shipping_lines() throws {
404+
// Given
405+
let remote = OrdersRemote(network: network)
406+
let shipping = ShippingLine(shippingID: 333, methodTitle: "Shipping", methodID: "other", total: "1.23", totalTax: "", taxes: [])
407+
let order = Order.fake().copy(shippingLines: [shipping])
408+
409+
// When
410+
remote.createOrder(siteID: 123, order: order, fields: [.shippingLines]) { result in }
411+
412+
// Then
413+
let request = try XCTUnwrap(network.requestsForResponseData.last as? JetpackRequest)
414+
let received = try XCTUnwrap(request.parameters["shipping_lines"] as? [[String: AnyHashable]]).first
415+
let expected: [String: AnyHashable] = [
416+
"id": shipping.shippingID,
417+
"method_title": shipping.methodTitle,
418+
"method_id": shipping.methodID ?? "",
419+
"total": shipping.total
420+
]
421+
assertEqual(received, expected)
422+
}
379423
}
380424

381425
private extension OrdersRemoteTests {

Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ target 'WooCommerce' do
4040
pod 'Gridicons', '~> 1.2.0'
4141

4242
# To allow pod to pick up beta versions use -beta. E.g., 1.1.7-beta.1
43-
pod 'WordPressAuthenticator', '~> 1.42.0'
43+
pod 'WordPressAuthenticator', '~> 1.43.1-beta'
4444
# pod 'WordPressAuthenticator', :git => 'https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git', :commit => ''
4545
# pod 'WordPressAuthenticator', :git => 'https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git', :branch => ''
4646
# pod 'WordPressAuthenticator', :path => '../WordPressAuthenticator-iOS'

Podfile.lock

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
PODS:
2-
- 1PasswordExtension (1.8.6)
32
- Alamofire (4.8.0)
43
- AppAuth (1.4.0):
54
- AppAuth/Core (= 1.4.0)
@@ -31,7 +30,7 @@ PODS:
3130
- GTMAppAuth (1.2.2):
3231
- AppAuth/Core (~> 1.4)
3332
- GTMSessionFetcher/Core (~> 1.5)
34-
- GTMSessionFetcher/Core (1.6.1)
33+
- GTMSessionFetcher/Core (1.7.0)
3534
- KeychainAccess (3.2.1)
3635
- Kingfisher (6.0.1)
3736
- lottie-ios (3.1.9)
@@ -49,8 +48,7 @@ PODS:
4948
- WordPress-Aztec-iOS (1.11.0)
5049
- WordPress-Editor-iOS (1.11.0):
5150
- WordPress-Aztec-iOS (= 1.11.0)
52-
- WordPressAuthenticator (1.42.0):
53-
- 1PasswordExtension (~> 1.8.6)
51+
- WordPressAuthenticator (1.43.1-beta.1):
5452
- Alamofire (~> 4.8)
5553
- CocoaLumberjack (~> 3.5)
5654
- GoogleSignIn (~> 6.0.1)
@@ -102,7 +100,7 @@ DEPENDENCIES:
102100
- Sourcery (~> 1.0.3)
103101
- StripeTerminal (~> 2.5)
104102
- WordPress-Editor-iOS (~> 1.11.0)
105-
- WordPressAuthenticator (~> 1.42.0)
103+
- WordPressAuthenticator (~> 1.43.1-beta)
106104
- WordPressKit (~> 4.40.0)
107105
- WordPressShared (~> 1.15)
108106
- WordPressUI (~> 1.12.4)
@@ -115,7 +113,6 @@ SPEC REPOS:
115113
https://github.com/wordpress-mobile/cocoapods-specs.git:
116114
- WordPressAuthenticator
117115
trunk:
118-
- 1PasswordExtension
119116
- Alamofire
120117
- AppAuth
121118
- Automattic-Tracks-iOS
@@ -156,7 +153,6 @@ SPEC REPOS:
156153
- ZendeskSupportSDK
157154

158155
SPEC CHECKSUMS:
159-
1PasswordExtension: f97cc80ae58053c331b2b6dc8843ba7103b33794
160156
Alamofire: 3ec537f71edc9804815215393ae2b1a8ea33a844
161157
AppAuth: 31bcec809a638d7bd2f86ea8a52bd45f6e81e7c7
162158
Automattic-Tracks-iOS: f5a6188ad8d00680748111466beabb0aea11f856
@@ -166,7 +162,7 @@ SPEC CHECKSUMS:
166162
GoogleSignIn: fd381840dbe7c1137aa6dc30849a5c3e070c034a
167163
Gridicons: 4455b9f366960121430e45997e32112ae49ffe1d
168164
GTMAppAuth: ad5c2b70b9a8689e1a04033c9369c4915bfcbe89
169-
GTMSessionFetcher: 36689134877faeb055b27dfa4ccc9ceaa42e029e
165+
GTMSessionFetcher: 43748f93435c2aa068b1cbe39655aaf600652e91
170166
KeychainAccess: d5470352939ced6d6f7fb51cb2e67aae51fc294f
171167
Kingfisher: adde87a4f74f6a3845395769354efff593581740
172168
lottie-ios: 3a3758ef5a008e762faec9c9d50a39842f26d124
@@ -181,7 +177,7 @@ SPEC CHECKSUMS:
181177
UIDeviceIdentifier: d0fee204f467dacf8808b7ac14ce43affeb271a5
182178
WordPress-Aztec-iOS: 050b34d4c3adfb7c60363849049b13d60683b348
183179
WordPress-Editor-iOS: 304098424f1051cb271546c99f906aac296b1b81
184-
WordPressAuthenticator: 06278534519c741ecea346f504ad8d08082bfb0d
180+
WordPressAuthenticator: adba93ef31576dcc0f72b8c0a8dfbd1c4467de99
185181
WordPressKit: 062e4f57ce871e2217b632a1f3cb0bbd54b5df6d
186182
WordPressShared: 5477f179c7fe03b5d574f91adda66f67d131827e
187183
WordPressUI: 9e470758bc3a4a25e94478c2babe106f4ae7315a
@@ -197,6 +193,6 @@ SPEC CHECKSUMS:
197193
ZendeskSupportProvidersSDK: 2bdf8544f7cd0fd4c002546f5704b813845beb2a
198194
ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba
199195

200-
PODFILE CHECKSUM: 1f574942620ff65ec3156586545d528d7b4b26b9
196+
PODFILE CHECKSUM: 0872fc8f8ec57fd5d53d7ae0937cbc20a279bb8a
201197

202198
COCOAPODS: 1.11.2

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
-----
55
- [*] Orders: In the experimental Order Creation feature, product variations added to a new order now show a list of their attributes. [https://github.com/woocommerce/woocommerce-ios/pull/6131]
66
- [*] Enlarged the tap area for the action button on the notice view. [https://github.com/woocommerce/woocommerce-ios/pull/6146]
7+
- [*] Reviews: Fixed crash on iPad when tapping the More button. [https://github.com/woocommerce/woocommerce-ios/pull/6187]
78

89
8.5
910
-----

0 commit comments

Comments
 (0)