Skip to content

notif: package info indirection #1143

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

Closed

Conversation

Abhisheksainii
Copy link

In this PR, I made the changes to indirect PackageInfo.fromPlatform through a method on ZulipBinding.

Steps I followed :

  1. Update the ZulipBinding to provide package info: Add a method in ZulipBinding to return the package name. This method will wrap the call to PackageInfo.fromPlatform() and make it test-friendly.

  2. Override the method in TestZulipBinding: In the TestZulipBinding, override getAppBundleId to return a mock or predefined value for testing.

  3. Refactor the code to use getAppBundleId: Replace the direct calls with the indirection from Zulip Binding class.

  4. Write a test for the above logic under a group called 'tokens'. The allow the grouping of all tests related to tokens, I created a separate group : tokens.

Fixes #407

@Abhisheksainii Abhisheksainii changed the title Fix/package info indirection notif: package info indirection Dec 12, 2024
@chrisbobbe
Copy link
Collaborator

Hi @Abhisheksainii, thanks for the PR. It will need to follow our Git style before it gets reviewed by a core team member.

@Abhisheksainii
Copy link
Author

Abhisheksainii commented Dec 13, 2024

@chrisbobbe changes made according to the git style.
Please check.

@Abhisheksainii Abhisheksainii force-pushed the fix/package-info-indirection branch from 75331d7 to 5970957 Compare December 13, 2024 16:13
Copy link
Member

@PIG208 PIG208 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @Abhisheksainii! Looks like there is a simplification to be made, because we already access and store packageInfo. It will probably require you to modify our copy of PackageInfo class by adding packageName to it.

@PIG208 PIG208 requested review from PIG208 and removed request for PIG208 December 17, 2024 23:32
@PIG208 PIG208 self-assigned this Dec 17, 2024
@PIG208 PIG208 added the maintainer review PR ready for review by Zulip maintainers label Dec 17, 2024
@Abhisheksainii
Copy link
Author

@PIG208 changes done as requested, kindly take a look at them.

@PIG208
Copy link
Member

PIG208 commented Dec 19, 2024

Thanks for the update. Please review the "commit style guide" referenced in the README and update your commits: https://github.com/zulip/zulip-flutter?tab=readme-ov-file#submitting-a-pull-request

Also, it looks like the CI is failing. Could you fix that?
Looks like the CI failure is not relevant to this PR.

@Abhisheksainii
Copy link
Author

Thanks for the update. Please review the "commit style guide" referenced in the README and update your commits: https://github.com/zulip/zulip-flutter?tab=readme-ov-file#submitting-a-pull-request

Also, it looks like the CI is failing. Could you fix that? Looks like the CI failure is not relevant to this PR.

@PIG208 I checked the commits and they pretty much explain what they do. Am I supposed to add some more description?

@gnprice
Copy link
Member

gnprice commented Dec 20, 2024

Please read the Zulip commit style guide, which is linked from the README where Zixuan pointed to.

@Abhisheksainii Abhisheksainii force-pushed the fix/package-info-indirection branch from c119c94 to 2cc9de6 Compare December 20, 2024 19:15
@Abhisheksainii
Copy link
Author

Abhisheksainii commented Dec 20, 2024

Thanks for the update. Please review the "commit style guide" referenced in the README and update your commits: https://github.com/zulip/zulip-flutter?tab=readme-ov-file#submitting-a-pull-request

Also, it looks like the CI is failing. Could you fix that? Looks like the CI failure is not relevant to this PR.

@PIG208 commits updated according to the style guide. Kindly review them
Thanks!

@Abhisheksainii Abhisheksainii force-pushed the fix/package-info-indirection branch 2 times, most recently from 3a87065 to ff11675 Compare December 21, 2024 06:19
@Abhisheksainii
Copy link
Author

@PIG208 kindly review the changes.

@PIG208
Copy link
Member

PIG208 commented Dec 23, 2024

Thanks for the update @Abhisheksainii! Left some comments.

@Abhisheksainii Abhisheksainii force-pushed the fix/package-info-indirection branch from ff11675 to 9849d78 Compare January 2, 2025 19:43
@Abhisheksainii
Copy link
Author

@PIG208 made changes as requested. Kindly review.

@PIG208 PIG208 self-requested a review January 9, 2025 09:07
Copy link
Member

@PIG208 PIG208 left a comment

Choose a reason for hiding this comment

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

Thanks for the update! Left some comments. In this PR's case, I think we should squash all commits into one, so that the implementation and the tests packed together for coherency.

@Abhisheksainii Abhisheksainii force-pushed the fix/package-info-indirection branch from 9849d78 to 90a7774 Compare January 22, 2025 09:50
@Abhisheksainii
Copy link
Author

@PIG208 made changes as requested. Kindly review.

Copy link
Member

@PIG208 PIG208 left a comment

Choose a reason for hiding this comment

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

Thanks for the update!

As I mentioned earlier, let's squash all commits into one.

I see that there are some comments marked as resolved that didn't actually get addressed in this update. Please be sure to double-check your changes before pushing.

@Abhisheksainii Abhisheksainii force-pushed the fix/package-info-indirection branch from 90a7774 to 6801944 Compare January 23, 2025 16:13
@Abhisheksainii Abhisheksainii force-pushed the fix/package-info-indirection branch from 6801944 to 75b9059 Compare January 23, 2025 16:15
@Abhisheksainii
Copy link
Author

@PIG208 changes made as requested. Kindly review

@Abhisheksainii Abhisheksainii force-pushed the fix/package-info-indirection branch from 75b9059 to 4141ae2 Compare January 25, 2025 06:22
@Abhisheksainii Abhisheksainii requested a review from PIG208 January 25, 2025 06:23
@Abhisheksainii Abhisheksainii force-pushed the fix/package-info-indirection branch from 4141ae2 to e421ebf Compare January 25, 2025 06:26
@Abhisheksainii
Copy link
Author

@PIG208 changes done as requested. Please review them

@gnprice
Copy link
Member

gnprice commented Jan 27, 2025

The commit in this PR is still quite messy and hard to read, even after four rounds of review (plus a fifth posted just now above). @Abhisheksainii in order for us to continue spending time reviewing your work, you need to start doing a better job of self-reviewing it first. See our guidelines:
https://zulip.readthedocs.io/en/latest/contributing/code-reviewing.html#reviewing-your-own-code
https://zulip.readthedocs.io/en/latest/contributing/reviewable-prs.html

For your next revision, I recommend you rewrite the change from scratch. (There's not very much code here anyway, so that isn't much work.) You can look back at the current revision for reference (and you should definitely pay attention to @PIG208's latest round of comments), but I recommend not copy-pasting anything and instead typing it out. The important thing is to think through each change you're making based on what it's accomplishing and what's needed.

Then when you're writing text like a test description or a commit message, make sure it accurately describes what the code is actually doing. In this revision they don't.

When you've finished writing a new version, re-read the whole thing carefully and edit as needed to make everything as clear and accurate as you can, and to make sure you've addressed all review comments. For detailed guidance, see our docs that I've linked above.

… registration

To fetch live value of appBundleId through Zulip Binding class, we made use of already establised PackageInfo class by introducing new parameter because using this version directly(final appBundleId = (await PackageInfo.fromPlatform()).packageName;) would break tests as it's directly calling a plugin. Fixes zulip#407

The reason for making packageInfoResult nullable in Zulip Binding class was to test the case where appId fallbacks to default appBundleId (com.zulip.flutter)
@Abhisheksainii Abhisheksainii force-pushed the fix/package-info-indirection branch from e421ebf to fead234 Compare January 30, 2025 03:50
@Abhisheksainii
Copy link
Author

Abhisheksainii commented Jan 30, 2025

@PIG208 made changes from scratch. Kindly review

@PIG208 do I need to make some changes?

@Abhisheksainii Abhisheksainii requested a review from PIG208 January 30, 2025 03:54
Copy link
Member

@PIG208 PIG208 left a comment

Choose a reason for hiding this comment

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

Thanks for the revision! Left a review. Since it doesn't seem ready yet, we won't prioritize this PR for some time until we move on to the next milestone.

prepareStore();
connection.prepare(json: {});

if(defaultTargetPlatform == TargetPlatform.iOS){
Copy link
Member

Choose a reason for hiding this comment

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

This check doesn't seem right. Because the debugDefaultTargetPlatformOverride doesn't get updated, the block inside never gets executed. The other tests use this because they use testAndroidIos instead of test.

Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
if(defaultTargetPlatform == TargetPlatform.iOS){
if (defaultTargetPlatform == TargetPlatform.iOS) {

Please also check for other spots for issues like this.

Copy link
Author

Choose a reason for hiding this comment

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

I found these instructions in testAndroidIos function :
final origTargetPlatform = debugDefaultTargetPlatformOverride;
addTearDown(() => debugDefaultTargetPlatformOverride = origTargetPlatform);
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;

what do you think of replicating them in the above test. It will look something like this:

prepareStore();
connection.prepare(json: {});

  final origTargetPlatform = debugDefaultTargetPlatformOverride;
  addTearDown(() {
    testBinding.reset();
    debugDefaultTargetPlatformOverride = origTargetPlatform;
  });

  debugDefaultTargetPlatformOverride = TargetPlatform.iOS;

  if (debugDefaultTargetPlatformOverride == TargetPlatform.iOS) {
    testBinding.packageInfoResult = null;
    await NotificationService.registerToken(connection, token: '012abc');
    checkLastRequestApns(token: '012abc', appid: 'com.zulip.flutter');
  }

Comment on lines +1088 to +1089
// This tests the case where packageInfo is null
// and default appBundleId gets passed to the [NotificationService.registerToken] method
Copy link
Member

Choose a reason for hiding this comment

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

Ideally the comment shouldn't be needed here, as the test code itself would be self-explanatory in most cases.

It would be better to have comments on the exact places where something might not be obvious to a reader.

testBinding.packageInfoResult=null;
await NotificationService.registerToken(connection, token: '012abc');
checkLastRequestApns(token: '012abc', appid: 'com.zulip.flutter');
addTearDown(testBinding.reset);
Copy link
Member

Choose a reason for hiding this comment

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

Usually this is called at the beginning of the test. addTearDown registers a callback function that gets called when the test is finished and "teared down", so there is no need to place it near the end.

@@ -149,8 +149,7 @@ class NotificationService {
await addFcmToken(connection, token: token);

case TargetPlatform.iOS:
const appBundleId = 'com.zulip.flutter'; // TODO(#407) find actual value live
await addApnsToken(connection, token: token, appid: appBundleId);
await addApnsToken(connection, token: token, appid: (await ZulipBinding.instance.packageInfo)?.packageName?? 'com.zulip.flutter');
Copy link
Member

Choose a reason for hiding this comment

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

Bumping #1143 (comment)

Let's include a assert(debugLog(…)) here with a TODO(log) comment.

It would be helpful to structure this with an if-statement first.

Suggested change
await addApnsToken(connection, token: token, appid: (await ZulipBinding.instance.packageInfo)?.packageName?? 'com.zulip.flutter');
final packageInfo = await ZulipBinding.instance.packageInfo;
if (packageInfo == null) {
assert(debugLog('missing packageInfo')); // TODO(log)
}
await addApnsToken(connection,
token: token, appid: packageInfo?.packageName ?? 'com.zulip.flutter');

Copy link
Author

@Abhisheksainii Abhisheksainii Feb 7, 2025

Choose a reason for hiding this comment

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

makes sense!
I also thought of adding it at first, but incase packageInfo becomes null, it would stop the execution which is ahead of the assert statement. Wouldn't that interrupt our test?

@gnprice
Copy link
Member

gnprice commented Mar 20, 2025

Thanks @Abhisheksainii for working on this. Because it looks like work here isn't continuing, I'm closing this PR to open up the issue for someone else to give it a try.

@gnprice gnprice closed this Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintainer review PR ready for review by Zulip maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

notif: Use live value for app ID on registering APNs token
4 participants