Skip to content

Commit f374495

Browse files
authored
[Woo POS] Fix two failing analytics tests (#16083)
2 parents e702542 + b1ca363 commit f374495

File tree

5 files changed

+80
-38
lines changed

5 files changed

+80
-38
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ end
99
gem 'danger-dangermattic', '~> 1.2'
1010
gem 'dotenv'
1111
# 2.217.0 includes a fix for Xcode 15 test results parsing in CI
12-
gem 'fastlane', '~> 2.217'
12+
gem 'fastlane', '~> 2.228'
1313
gem 'fastlane-plugin-firebase_app_distribution', '~> 0.10'
1414
gem 'fastlane-plugin-sentry', '~> 1.0'
1515
# This comment avoids typing to switch to a development version for testing.

Gemfile.lock

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,27 @@ GEM
2323
artifactory (3.0.17)
2424
ast (2.4.2)
2525
atomos (0.1.3)
26-
aws-eventstream (1.3.0)
27-
aws-partitions (1.1029.0)
28-
aws-sdk-core (3.214.1)
26+
aws-eventstream (1.4.0)
27+
aws-partitions (1.1154.0)
28+
aws-sdk-core (3.232.0)
2929
aws-eventstream (~> 1, >= 1.3.0)
3030
aws-partitions (~> 1, >= 1.992.0)
3131
aws-sigv4 (~> 1.9)
32+
base64
33+
bigdecimal
3234
jmespath (~> 1, >= 1.6.1)
33-
aws-sdk-kms (1.96.0)
34-
aws-sdk-core (~> 3, >= 3.210.0)
35+
logger
36+
aws-sdk-kms (1.112.0)
37+
aws-sdk-core (~> 3, >= 3.231.0)
3538
aws-sigv4 (~> 1.5)
36-
aws-sdk-s3 (1.176.1)
37-
aws-sdk-core (~> 3, >= 3.210.0)
39+
aws-sdk-s3 (1.198.0)
40+
aws-sdk-core (~> 3, >= 3.231.0)
3841
aws-sdk-kms (~> 1)
3942
aws-sigv4 (~> 1.5)
40-
aws-sigv4 (1.10.1)
43+
aws-sigv4 (1.12.1)
4144
aws-eventstream (~> 1, >= 1.0.2)
4245
babosa (1.0.4)
43-
base64 (0.2.0)
46+
base64 (0.3.0)
4447
benchmark (0.4.1)
4548
bigdecimal (3.2.2)
4649
buildkit (1.6.1)
@@ -85,7 +88,7 @@ GEM
8588
rubocop (~> 1.0)
8689
declarative (0.0.20)
8790
diffy (3.4.4)
88-
digest-crc (0.6.5)
91+
digest-crc (0.7.0)
8992
rake (>= 12.0.0, < 14.0.0)
9093
domain_name (0.6.20240107)
9194
dotenv (2.8.1)
@@ -108,12 +111,12 @@ GEM
108111
faraday (>= 0.8.0)
109112
http-cookie (~> 1.0.0)
110113
faraday-em_http (1.0.0)
111-
faraday-em_synchrony (1.0.0)
114+
faraday-em_synchrony (1.0.1)
112115
faraday-excon (1.1.0)
113116
faraday-http-cache (2.5.1)
114117
faraday (>= 0.8)
115118
faraday-httpclient (1.0.1)
116-
faraday-multipart (1.1.0)
119+
faraday-multipart (1.1.1)
117120
multipart-post (~> 2.0)
118121
faraday-net_http (1.0.2)
119122
faraday-net_http_persistent (1.2.0)
@@ -122,8 +125,8 @@ GEM
122125
faraday-retry (1.0.3)
123126
faraday_middleware (1.2.1)
124127
faraday (~> 1.0)
125-
fastimage (2.3.1)
126-
fastlane (2.226.0)
128+
fastimage (2.4.0)
129+
fastlane (2.228.0)
127130
CFPropertyList (>= 2.3, < 4.0.0)
128131
addressable (>= 2.8, < 3.0.0)
129132
artifactory (~> 3.0)
@@ -163,7 +166,7 @@ GEM
163166
tty-spinner (>= 0.8.0, < 1.0.0)
164167
word_wrap (~> 1.0.0)
165168
xcodeproj (>= 1.13.0, < 2.0.0)
166-
xcpretty (~> 0.4.0)
169+
xcpretty (~> 0.4.1)
167170
xcpretty-travis-formatter (>= 0.0.3, < 2.0.0)
168171
fastlane-plugin-firebase_app_distribution (0.10.0)
169172
google-apis-firebaseappdistribution_v1 (~> 0.3.0)
@@ -213,12 +216,12 @@ GEM
213216
google-apis-core (>= 0.11.0, < 2.a)
214217
google-apis-storage_v1 (0.31.0)
215218
google-apis-core (>= 0.11.0, < 2.a)
216-
google-cloud-core (1.7.1)
219+
google-cloud-core (1.8.0)
217220
google-cloud-env (>= 1.0, < 3.a)
218221
google-cloud-errors (~> 1.0)
219222
google-cloud-env (1.6.0)
220223
faraday (>= 0.17.3, < 3.0)
221-
google-cloud-errors (1.4.0)
224+
google-cloud-errors (1.5.0)
222225
google-cloud-storage (1.47.0)
223226
addressable (~> 2.8)
224227
digest-crc (~> 0.4)
@@ -236,13 +239,14 @@ GEM
236239
highline (2.0.3)
237240
http-cookie (1.0.8)
238241
domain_name (~> 0.5)
239-
httpclient (2.8.3)
242+
httpclient (2.9.0)
243+
mutex_m
240244
i18n (1.14.7)
241245
concurrent-ruby (~> 1.0)
242246
java-properties (0.3.0)
243247
jmespath (1.6.2)
244-
json (2.9.1)
245-
jwt (2.10.1)
248+
json (2.13.2)
249+
jwt (2.10.2)
246250
base64
247251
kramdown (2.5.1)
248252
rexml (>= 3.3.9)
@@ -254,11 +258,12 @@ GEM
254258
mini_mime (1.1.5)
255259
mini_portile2 (2.8.9)
256260
minitest (5.25.5)
257-
multi_json (1.15.0)
261+
multi_json (1.17.0)
258262
multipart-post (2.4.1)
263+
mutex_m (0.3.0)
259264
nanaimo (0.4.0)
260265
nap (1.1.0)
261-
naturally (2.2.1)
266+
naturally (2.3.0)
262267
nkf (0.2.0)
263268
nokogiri (1.18.8)
264269
mini_portile2 (~> 2.8.2)
@@ -281,7 +286,7 @@ GEM
281286
highline (>= 1.6)
282287
options (~> 2.3.0)
283288
pstore (0.1.3)
284-
public_suffix (4.0.7)
289+
public_suffix (6.0.2)
285290
racc (1.8.1)
286291
rainbow (3.1.1)
287292
rake (12.3.3)
@@ -294,7 +299,7 @@ GEM
294299
trailblazer-option (>= 0.1.1, < 0.2.0)
295300
uber (< 0.2.0)
296301
retriable (3.1.2)
297-
rexml (3.4.0)
302+
rexml (3.4.2)
298303
rmagick (4.3.0)
299304
rouge (3.28.0)
300305
rubocop (1.68.0)
@@ -313,16 +318,16 @@ GEM
313318
rubocop (~> 1.0)
314319
ruby-progressbar (1.13.0)
315320
ruby2_keywords (0.0.5)
316-
rubyzip (2.3.2)
321+
rubyzip (2.4.1)
317322
sawyer (0.9.2)
318323
addressable (>= 2.3.5)
319324
faraday (>= 0.17.3, < 3)
320325
securerandom (0.4.1)
321326
security (0.1.5)
322-
signet (0.19.0)
327+
signet (0.21.0)
323328
addressable (~> 2.8)
324329
faraday (>= 0.17.5, < 3.a)
325-
jwt (>= 1.5, < 3.0)
330+
jwt (>= 1.5, < 4.0)
326331
multi_json (~> 1.10)
327332
simctl (1.6.10)
328333
CFPropertyList
@@ -352,7 +357,7 @@ GEM
352357
colored2 (~> 3.1)
353358
nanaimo (~> 0.4.0)
354359
rexml (>= 3.3.6, < 4.0)
355-
xcpretty (0.4.0)
360+
xcpretty (0.4.1)
356361
rouge (~> 3.28.0)
357362
xcpretty-travis-formatter (1.0.1)
358363
xcpretty (~> 0.2, >= 0.0.7)
@@ -366,7 +371,7 @@ PLATFORMS
366371
DEPENDENCIES
367372
danger-dangermattic (~> 1.2)
368373
dotenv
369-
fastlane (~> 2.217)
374+
fastlane (~> 2.228)
370375
fastlane-plugin-firebase_app_distribution (~> 0.10)
371376
fastlane-plugin-sentry (~> 1.0)
372377
fastlane-plugin-wpmreleasetoolkit (~> 13.3, >= 13.3.1)

WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleOrderControllerTests.swift

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,11 @@ struct PointOfSaleOrderControllerTests {
182182

183183
@Test func sendReceipt_when_there_is_no_order_then_will_not_trigger() async throws {
184184
// Given
185+
let mockFeatureFlagService = MockFeatureFlagService()
186+
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = true
185187
let sut = PointOfSaleOrderController(orderService: mockOrderService,
186-
receiptService: mockReceiptService)
188+
receiptService: mockReceiptService,
189+
featureFlagService: mockFeatureFlagService)
187190
let email = "[email protected]"
188191

189192
// When
@@ -199,8 +202,11 @@ struct PointOfSaleOrderControllerTests {
199202

200203
@Test func sendReceipt_calls_both_updateOrder_and_sendReceipt() async throws {
201204
// Given
205+
let mockFeatureFlagService = MockFeatureFlagService()
206+
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = true
202207
let sut = PointOfSaleOrderController(orderService: mockOrderService,
203-
receiptService: mockReceiptService)
208+
receiptService: mockReceiptService,
209+
featureFlagService: mockFeatureFlagService)
204210
let order = Order.fake()
205211
let recipientEmail = "[email protected]"
206212
mockOrderService.orderToReturn = order
@@ -220,7 +226,8 @@ struct PointOfSaleOrderControllerTests {
220226
do {
221227
// Given/When
222228
let sut = PointOfSaleOrderController(orderService: mockOrderService,
223-
receiptService: mockReceiptService)
229+
receiptService: mockReceiptService,
230+
celebration: MockPaymentCaptureCelebration())
224231
try await sut.collectCashPayment(changeDueAmount: nil)
225232
} catch let error as PointOfSaleOrderController.PointOfSaleOrderControllerError {
226233
// Then
@@ -253,7 +260,8 @@ struct PointOfSaleOrderControllerTests {
253260
@Test func collectCashPayment_passes_changeDueAmount_to_order_service() async throws {
254261
// Given
255262
let sut = PointOfSaleOrderController(orderService: mockOrderService,
256-
receiptService: mockReceiptService)
263+
receiptService: mockReceiptService,
264+
celebration: MockPaymentCaptureCelebration())
257265

258266
let orderItem = OrderItem.fake()
259267
let fakeOrder = Order.fake().copy(items: [orderItem])
@@ -600,7 +608,8 @@ struct PointOfSaleOrderControllerTests {
600608

601609
let sut = PointOfSaleOrderController(orderService: orderService,
602610
receiptService: MockReceiptService(),
603-
analytics: mockAnalytics)
611+
analytics: mockAnalytics,
612+
celebration: MockPaymentCaptureCelebration())
604613

605614
// In order to test the order controller failure we need to succeed first in creating a successful order:
606615
let orderItem = OrderItem.fake()
@@ -629,15 +638,21 @@ struct PointOfSaleOrderControllerTests {
629638
version: "10.0.0-dev",
630639
active: true))
631640

641+
let mockFeatureFlagService = MockFeatureFlagService()
642+
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = true
643+
632644
let sut = PointOfSaleOrderController(orderService: orderService,
633645
receiptService: receiptService,
634646
analytics: analytics,
647+
featureFlagService: mockFeatureFlagService,
635648
pluginsService: mockPluginsService)
636649
let order = Order.fake()
637650
orderService.orderToReturn = order
638651

639652
// We need an existing order before we can send a receipt
640653
await sut.syncOrder(for: .init(purchasableItems: [makeItem()]), retryHandler: { })
654+
analyticsProvider.receivedEvents.removeAll()
655+
analyticsProvider.receivedProperties.removeAll()
641656

642657
// When
643658
try await sut.sendReceipt(recipientEmail: "[email protected]")
@@ -649,9 +664,12 @@ struct PointOfSaleOrderControllerTests {
649664

650665
@Test func sendReceipt_without_order_tracks_failure_without_eligible_for_pos_receipt() async throws {
651666
// Given
667+
let mockFeatureFlagService = MockFeatureFlagService()
668+
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = true
652669
let sut = PointOfSaleOrderController(orderService: orderService,
653670
receiptService: receiptService,
654-
analytics: analytics)
671+
analytics: analytics,
672+
featureFlagService: mockFeatureFlagService)
655673

656674
// When
657675
do {
@@ -671,9 +689,12 @@ struct PointOfSaleOrderControllerTests {
671689
version: "10.0.0-dev",
672690
active: true))
673691

692+
let mockFeatureFlagService = MockFeatureFlagService()
693+
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = true
674694
let sut = PointOfSaleOrderController(orderService: orderService,
675695
receiptService: receiptService,
676696
analytics: analytics,
697+
featureFlagService: mockFeatureFlagService,
677698
pluginsService: mockPluginsService)
678699

679700
receiptService.sendReceiptResult = .failure(DotcomError.unknown(code: "test_error", message: "Test error"))
@@ -683,6 +704,8 @@ struct PointOfSaleOrderControllerTests {
683704

684705
// We need an existing order before we can send a receipt
685706
await sut.syncOrder(for: .init(purchasableItems: [makeItem()]), retryHandler: { })
707+
analyticsProvider.receivedEvents.removeAll()
708+
analyticsProvider.receivedProperties.removeAll()
686709

687710
// When
688711
do {

WooCommerce/WooCommerceTests/POS/Mocks/MockPOSCollectOrderPaymentAnalyticsTracker.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ final class MockPOSCollectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAn
2828
// no-op
2929
}
3030

31+
var didCallTrackSuccessfulCashPayment = false
3132
func trackSuccessfulCashPayment() {
32-
// no-op
33+
didCallTrackSuccessfulCashPayment = true
3334
}
3435

3536
var connectedReaderModel: String?

WooCommerce/WooCommerceTests/POS/Models/PointOfSaleAggregateModelTests.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,20 @@ struct PointOfSaleAggregateModelTests {
906906
await sut.startCashPayment()
907907

908908
// Then
909-
#expect(mockAnalyticsProvider.receivedEvents.first(where: { $0 == "cash_payment_tapped" }) != nil)
909+
#expect(mockAnalyticsProvider.receivedEvents.first(where: { $0 == "checkout_cash_payment_tapped" }) != nil)
910+
}
911+
912+
@Test func collectCashPayment_when_invoked_tracks_expected_event() async throws {
913+
// Given
914+
let analyticsTracker = MockPOSCollectOrderPaymentAnalyticsTracker()
915+
let sut = makePointOfSaleAggregateModel(orderController: orderController,
916+
collectOrderPaymentAnalyticsTracker: analyticsTracker)
917+
918+
// When
919+
try await sut.collectCashPayment(changeDueAmount: "0.00")
920+
921+
// Then
922+
#expect(analyticsTracker.didCallTrackSuccessfulCashPayment == true)
910923
}
911924
}
912925

0 commit comments

Comments
 (0)