Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Modules/Sources/Experiments/DefaultFeatureFlagService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ public struct DefaultFeatureFlagService: FeatureFlagService {
return false
case .inventoryProductLabelsInPOS:
return false
case .pointOfSaleReceipts:
return true
case .productImageOptimizedHandling:
return true
case .pointOfSaleAsATabi2:
Expand Down
4 changes: 0 additions & 4 deletions Modules/Sources/Experiments/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ public enum FeatureFlag: Int {
///
case inventoryProductLabelsInPOS

/// Enables sending POS specific email receipts for eligible stores
///
case pointOfSaleReceipts

/// Enables displaying POS as a tab in the tab bar for stores in eligible countries
///
case pointOfSaleAsATabi2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation
import Observation
import protocol Experiments.FeatureFlagService
import protocol Yosemite.StoresManager
import protocol Yosemite.POSOrderServiceProtocol
import protocol Yosemite.POSReceiptServiceProtocol
Expand Down Expand Up @@ -45,7 +44,6 @@ protocol PointOfSaleOrderControllerProtocol {
stores: StoresManager = ServiceLocator.stores,
currencySettings: CurrencySettings = ServiceLocator.currencySettings,
analytics: Analytics = ServiceLocator.analytics,
featureFlagService: FeatureFlagService = ServiceLocator.featureFlagService,
pluginsService: PluginsServiceProtocol = PluginsService(storageManager: ServiceLocator.storageManager),
celebration: PaymentCaptureCelebrationProtocol = PaymentCaptureCelebration()) {
self.orderService = orderService
Expand All @@ -54,7 +52,6 @@ protocol PointOfSaleOrderControllerProtocol {
self.storeCurrency = currencySettings.currencyCode
self.currencyFormatter = CurrencyFormatter(currencySettings: currencySettings)
self.analytics = analytics
self.featureFlagService = featureFlagService
self.pluginsService = pluginsService
self.celebration = celebration
}
Expand All @@ -67,7 +64,6 @@ protocol PointOfSaleOrderControllerProtocol {
private let storeCurrency: CurrencyCode
private let analytics: Analytics
private let stores: StoresManager
private let featureFlagService: FeatureFlagService
private let pluginsService: PluginsServiceProtocol

private(set) var orderState: PointOfSaleInternalOrderState = .idle
Expand Down Expand Up @@ -110,29 +106,23 @@ protocol PointOfSaleOrderControllerProtocol {

@MainActor
func sendReceipt(recipientEmail: String) async throws {
var isEligibleForPOSReceipt: Bool?
var isEligibleForPOSReceipt: Bool = false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAU we have no reason for this to be nil, since it's either eligible or it isn't. Also allows to simplify the value we pass to the catch block and the track event.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, if there was no order, or orderService.updatePOSOrder threw an error, we'd track the receiptEmailFailed event without eligible_for_pos_receipt (thanks to the compactMapValues.)

Now we'll log it as false even if the real answer would have been true.

Perhaps we should just set the isEligible at the top instead of after updating the order. The only thing it uses is the siteID, which isn't going to change from the order update, surely.

do {
guard let order else {
throw PointOfSaleOrderControllerError.noOrder
}

try await orderService.updatePOSOrder(order: order, recipientEmail: recipientEmail)

let posReceiptEligibility: Bool
if featureFlagService.isFeatureFlagEnabled(.pointOfSaleReceipts) {
posReceiptEligibility = isPluginSupported(
.wooCommerce,
minimumVersion: POSReceiptEligibilityConstants.wcPluginMinimumVersion,
siteID: order.siteID
)
} else {
posReceiptEligibility = false
}
isEligibleForPOSReceipt = posReceiptEligibility
isEligibleForPOSReceipt = isPluginSupported(
.wooCommerce,
minimumVersion: POSReceiptEligibilityConstants.wcPluginMinimumVersion,
siteID: order.siteID
)

try await receiptService.sendReceipt(order: order, recipientEmail: recipientEmail, isEligibleForPOSReceipt: posReceiptEligibility)
try await receiptService.sendReceipt(order: order, recipientEmail: recipientEmail, isEligibleForPOSReceipt: isEligibleForPOSReceipt)

analytics.track(.receiptEmailSuccess, withProperties: ["eligible_for_pos_receipt": posReceiptEligibility])
analytics.track(.receiptEmailSuccess, withProperties: ["eligible_for_pos_receipt": isEligibleForPOSReceipt])
} catch {
let properties = [
"eligible_for_pos_receipt": isEligibleForPOSReceipt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,8 @@ struct PointOfSaleOrderControllerTests {

@Test func sendReceipt_when_there_is_no_order_then_will_not_trigger() async throws {
// Given
let mockFeatureFlagService = MockFeatureFlagService()
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = true
let sut = PointOfSaleOrderController(orderService: mockOrderService,
receiptService: mockReceiptService,
featureFlagService: mockFeatureFlagService)
receiptService: mockReceiptService)
let email = "[email protected]"

// When
Expand All @@ -202,11 +199,8 @@ struct PointOfSaleOrderControllerTests {

@Test func sendReceipt_calls_both_updateOrder_and_sendReceipt() async throws {
// Given
let mockFeatureFlagService = MockFeatureFlagService()
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = true
let sut = PointOfSaleOrderController(orderService: mockOrderService,
receiptService: mockReceiptService,
featureFlagService: mockFeatureFlagService)
receiptService: mockReceiptService)
let order = Order.fake()
let recipientEmail = "[email protected]"
mockOrderService.orderToReturn = order
Expand Down Expand Up @@ -638,13 +632,9 @@ struct PointOfSaleOrderControllerTests {
version: "10.0.0-dev",
active: true))

let mockFeatureFlagService = MockFeatureFlagService()
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = true

let sut = PointOfSaleOrderController(orderService: orderService,
receiptService: receiptService,
analytics: analytics,
featureFlagService: mockFeatureFlagService,
pluginsService: mockPluginsService)
let order = Order.fake()
orderService.orderToReturn = order
Expand All @@ -664,20 +654,17 @@ struct PointOfSaleOrderControllerTests {

@Test func sendReceipt_without_order_tracks_failure_without_eligible_for_pos_receipt() async throws {
// Given
let mockFeatureFlagService = MockFeatureFlagService()
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = true
let sut = PointOfSaleOrderController(orderService: orderService,
receiptService: receiptService,
analytics: analytics,
featureFlagService: mockFeatureFlagService)
analytics: analytics)

// When
do {
try await sut.sendReceipt(recipientEmail: "[email protected]")
} catch {
// Then
let indexOfEvent = try #require(analyticsProvider.receivedEvents.firstIndex(where: { $0 == "receipt_email_failed" }))
#expect(analyticsProvider.receivedProperties[indexOfEvent]["eligible_for_pos_receipt"] == nil)
#expect(analyticsProvider.receivedProperties[indexOfEvent]["eligible_for_pos_receipt"] as? Bool == false)
}
}

Expand All @@ -689,12 +676,9 @@ struct PointOfSaleOrderControllerTests {
version: "10.0.0-dev",
active: true))

let mockFeatureFlagService = MockFeatureFlagService()
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = true
let sut = PointOfSaleOrderController(orderService: orderService,
receiptService: receiptService,
analytics: analytics,
featureFlagService: mockFeatureFlagService,
pluginsService: mockPluginsService)

receiptService.sendReceiptResult = .failure(DotcomError.unknown(code: "test_error", message: "Test error"))
Expand Down Expand Up @@ -723,13 +707,11 @@ struct PointOfSaleOrderControllerTests {
struct ReceiptTests {
private let mockOrderService = MockPOSOrderService()

@Test("Eligible core plugin versions with feature flag enabled", arguments: Constants.eligibleWCPluginVersions)
func sendReceipt_when_feature_flag_enabled_and_eligible_plugin_version_sets_isEligibleForPOSReceipt_true(wcPluginVersion: String) async throws {
@Test("Eligible core plugin versions", arguments: Constants.eligibleWCPluginVersions)
func sendReceipt_when_eligible_plugin_version_sets_isEligibleForPOSReceipt_true(wcPluginVersion: String) async throws {
// Given
let mockReceiptService = MockReceiptService()
let mockFeatureFlagService = MockFeatureFlagService()
let mockPluginsService = MockPluginsService()
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = true
mockPluginsService.setMockPlugin(.wooCommerce,
systemPlugin: SystemPlugin.fake().copy(plugin: "woocommerce/woocommerce.php",
version: wcPluginVersion,
Expand All @@ -738,7 +720,6 @@ struct PointOfSaleOrderControllerTests {
let sut = PointOfSaleOrderController(orderService: mockOrderService,
receiptService: mockReceiptService,
analytics: ServiceLocator.analytics,
featureFlagService: mockFeatureFlagService,
pluginsService: mockPluginsService)
mockOrderService.orderToReturn = Order.fake()

Expand All @@ -753,47 +734,11 @@ struct PointOfSaleOrderControllerTests {
#expect(mockReceiptService.spyIsEligibleForPOSReceipt == true)
}

@Test(
"All core plugin versions with feature flag disabled",
arguments: Constants.eligibleWCPluginVersions + Constants.ineligibleWCPluginVersions
)
func sendReceipt_when_feature_flag_disabled_and_eligible_plugin_version_sets_isEligibleForPOSReceipt_false(wcPluginVersion: String) async throws {
// Given
let mockReceiptService = MockReceiptService()
let mockFeatureFlagService = MockFeatureFlagService()
let mockPluginsService = MockPluginsService()
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = false
// Plugin setup is irrelevant when feature flag is disabled
mockPluginsService.setMockPlugin(.wooCommerce,
systemPlugin: SystemPlugin.fake().copy(plugin: "woocommerce/woocommerce.php",
version: wcPluginVersion,
active: true))

let sut = PointOfSaleOrderController(orderService: mockOrderService,
receiptService: mockReceiptService,
analytics: ServiceLocator.analytics,
featureFlagService: mockFeatureFlagService,
pluginsService: mockPluginsService)
mockOrderService.orderToReturn = Order.fake()

// We need an existing order before we can update its email, and send a receipt:
await sut.syncOrder(for: .init(purchasableItems: [makeItem()]), retryHandler: { })

// When
try await sut.sendReceipt(recipientEmail: "[email protected]")

// Then
#expect(mockReceiptService.sendReceiptWasCalled == true)
#expect(mockReceiptService.spyIsEligibleForPOSReceipt == false)
}

@Test("Ineligible core plugin versions with feature flag enabled", arguments: Constants.ineligibleWCPluginVersions)
func sendReceipt_when_feature_flag_enabled_and_ineligible_plugin_version_sets_isEligibleForPOSReceipt_false(wcPluginVersion: String) async throws {
func sendReceipt_when_ineligible_plugin_version_sets_isEligibleForPOSReceipt_false(wcPluginVersion: String) async throws {
// Given
let mockReceiptService = MockReceiptService()
let mockFeatureFlagService = MockFeatureFlagService()
let mockPluginsService = MockPluginsService()
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = true
mockPluginsService.setMockPlugin(.wooCommerce,
systemPlugin: SystemPlugin.fake().copy(plugin: "woocommerce/woocommerce.php",
version: wcPluginVersion,
Expand All @@ -802,7 +747,6 @@ struct PointOfSaleOrderControllerTests {
let sut = PointOfSaleOrderController(orderService: mockOrderService,
receiptService: mockReceiptService,
analytics: ServiceLocator.analytics,
featureFlagService: mockFeatureFlagService,
pluginsService: mockPluginsService)
mockOrderService.orderToReturn = Order.fake()

Expand All @@ -817,23 +761,20 @@ struct PointOfSaleOrderControllerTests {
#expect(mockReceiptService.spyIsEligibleForPOSReceipt == false)
}

@Test("Unavailable core plugin with feature flag enabled",
@Test("Unavailable core plugin",
arguments: [
SystemPlugin.fake().copy(plugin: "woocommerce/woocommerce.php", active: false),
nil
])
func sendReceipt_when_feature_flag_enabled_and_plugin_unavailable_sets_isEligibleForPOSReceipt_false(plugin: SystemPlugin?) async throws {
func sendReceipt_when_plugin_unavailable_sets_isEligibleForPOSReceipt_false(plugin: SystemPlugin?) async throws {
// Given
let mockReceiptService = MockReceiptService()
let mockFeatureFlagService = MockFeatureFlagService()
let mockPluginsService = MockPluginsService()
mockFeatureFlagService.isFeatureFlagEnabledReturnValue[.pointOfSaleReceipts] = true
mockPluginsService.setMockPlugin(.wooCommerce, systemPlugin: plugin)

let sut = PointOfSaleOrderController(orderService: mockOrderService,
receiptService: mockReceiptService,
analytics: ServiceLocator.analytics,
featureFlagService: mockFeatureFlagService,
pluginsService: mockPluginsService)
mockOrderService.orderToReturn = Order.fake()

Expand Down