woocommerce / woocommerce-ios

WooCommerce iOS app
https://www.woocommerce.com/mobile
GNU General Public License v2.0
312 stars 113 forks source link

Make 'fetchSystemPluginWithPath' calls more robust to API changes #13708

Open staskus opened 2 months ago

staskus commented 2 months ago

Describe the bug

Some parts of the app rely on 'fetchSystemPluginWithPath' calls which could break if API starts returning a different path. Example:

We call this method with a hardcoded path we define in the code. We should either improve fetchSystemPluginWith to be more flexible or rely on a different identifier than path.

        guard ServiceLocator.featureFlagService.isFeatureFlagEnabled(.wooPaymentsDepositsOverviewInPaymentsMenu),
              let depositService = dependencies.wooPaymentsDepositService,
              await dependencies.systemStatusService.fetchSystemPluginWithPath(siteID: siteID,
                                                                               pluginPath: WooConstants.wooPaymentsPluginPath) != nil else {
            shouldShowDepositSummary = false
            return
        }
    func checkIfGiftCardsPluginIsActive() async -> Bool {
        guard featureFlagService.isFeatureFlagEnabled(.giftCardInOrderForm) else {
            return false
        }
        return await withCheckedContinuation { continuation in
            stores.dispatch(SystemStatusAction.fetchSystemPluginWithPath(siteID: siteID, pluginPath: SystemPluginPaths.giftCards) { plugin in
                continuation.resume(returning: plugin?.active == true)
            })
        }
    }

To Reproduce Steps to reproduce the behavior:

  1. Install WooCommerce 9.2.0
  2. Enable Gift Card plugin woocommerce-gift-cards/woocommerce-gift-cards
  3. Launch the app
  4. Make an order
  5. Add a breakpoint on checkIfGiftCardsPluginIsActive
  6. Notice that the plugin is not found since the path is different

Screenshots If applicable, add screenshots to help explain your problem.

Expected behavior A clear and concise description of what you expected to happen.

Isolating the problem (mark completed items with an [x]):

Mobile Environment Please include:

WordPress Environment

``` Copy and paste the system status report from **WooCommerce > System Status** in WordPress admin. ```
dangermattic commented 2 months ago

🚫 Please add a type label (e.g. type: enhancement) and a feature label (e.g. feature: stats) to this issue.