Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt new way of getting notification data in PushNotificationBackgroundSynchronizer #13917

Merged

Conversation

bozidarsevo
Copy link
Contributor

@bozidarsevo bozidarsevo commented Sep 10, 2024

Closes: #13852

Description

Since we might already have note in the push notification (parsed from note_full_data part of the payload) we can check if we already have orderID in it without the need of syncronizing all the notifications and avoid extra network calls.
If we have the orderID we can go directly to syncronizing that exact order.

In this PR we use that ability and we use orderID from the note if we have that property set/loaded.

Testing information

Since this PR changes are not visible from the UI, testing can be done by adding some breakpoints in the PushNotificationBackgroundSynchronizer:

  • add breakpoint to line 40 -> orderID = Int64(noteOrderID)
  • run the app from Xcode
  • put the app in the background
  • get a new order notification
  • check that sync() function in PushNotificationBackgroundSynchronizer is called and debugger stops on that breakpoint at line 40
  • check that the notification has the proper `orderID
Screenshot 2024-09-12 at 11 39 12

Main breakpoint:

Screenshot 2024-09-12 at 11 39 17
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on all devices (phone/tablet) and no regressions are added.

@bozidarsevo bozidarsevo added the type: enhancement A request for an enhancement. label Sep 10, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Sep 10, 2024

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr13917-096108a
Version20.3
Bundle IDcom.automattic.alpha.woocommerce
Commit096108a
App Center BuildWooCommerce - Prototype Builds #10863
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Comment on lines +38 to +41
if let note = pushNotification.note,
let noteOrderID = note.meta.identifier(forKey: .order) {
orderID = Int64(noteOrderID)
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This the only change, checking if we already have the orderID in the notification note property.

@bozidarsevo bozidarsevo marked this pull request as ready for review September 12, 2024 09:20
@bozidarsevo bozidarsevo added this to the 20.4 milestone Sep 12, 2024
Copy link
Contributor

@Ecarrion Ecarrion left a comment

Choose a reason for hiding this comment

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

Good job @bozidarsevo, code looks good and tests well!

However, before approving, I think we can add a unit test on the PushNotificationBackgroundSynchronizerTests file.

@bozidarsevo
Copy link
Contributor Author

However, before approving, I think we can add a unit test on the PushNotificationBackgroundSynchronizerTests file.

What do you think, what kind of test case would be ok?
Maybe to check that synchronizeNotifications() was not called if the push notification has the orderID, or some other test?

@Ecarrion
Copy link
Contributor

However, before approving, I think we can add a unit test on the PushNotificationBackgroundSynchronizerTests file.

What do you think, what kind of test case would be ok? Maybe to check that synchronizeNotifications() was not called if the push notification has the orderID, or some other test?

I was thinking on something like:

func test_synchronizer_stores_order_notification_when_order_comes_inside_notification() {
    
    // Given
    mock_network_requests_without_notifications_endpoint()
    
    // When
    initialize_synchronizer_with_full_notification_data()
    
    // Then
    check_that_order_is_correctly_stored()
}

Does that make sense?

@Ecarrion Ecarrion self-assigned this Sep 12, 2024
@wpmobilebot wpmobilebot modified the milestones: 20.4, 20.5 Sep 13, 2024
@wpmobilebot
Copy link
Collaborator

Version 20.4 has now entered code-freeze, so the milestone of this PR has been updated to 20.5.

@bozidarsevo bozidarsevo merged commit c03539f into trunk Sep 13, 2024
15 of 16 checks passed
@bozidarsevo bozidarsevo deleted the issue/13852-PushNotificationBackgroundSynchronizer-tweaks branch September 13, 2024 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adopt new way of getting notification data in PushNotificationBackgroundSynchronizer
3 participants