-
Notifications
You must be signed in to change notification settings - Fork 305
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
notif: package info indirection #1143
Conversation
Hi @Abhisheksainii, thanks for the PR. It will need to follow our Git style before it gets reviewed by a core team member. |
@chrisbobbe changes made according to the git style. |
75331d7
to
5970957
Compare
There was a problem hiding this 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 changes done as requested, kindly take a look at them. |
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
|
@PIG208 I checked the commits and they pretty much explain what they do. Am I supposed to add some more description? |
Please read the Zulip commit style guide, which is linked from the README where Zixuan pointed to. |
c119c94
to
2cc9de6
Compare
@PIG208 commits updated according to the style guide. Kindly review them |
3a87065
to
ff11675
Compare
@PIG208 kindly review the changes. |
Thanks for the update @Abhisheksainii! Left some comments. |
ff11675
to
9849d78
Compare
@PIG208 made changes as requested. Kindly review. |
There was a problem hiding this 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.
9849d78
to
90a7774
Compare
@PIG208 made changes as requested. Kindly review. |
There was a problem hiding this 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.
90a7774
to
6801944
Compare
6801944
to
75b9059
Compare
@PIG208 changes made as requested. Kindly review |
75b9059
to
4141ae2
Compare
4141ae2
to
e421ebf
Compare
@PIG208 changes done as requested. Please review them |
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: 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)
e421ebf
to
fead234
Compare
There was a problem hiding this 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){ |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
if(defaultTargetPlatform == TargetPlatform.iOS){ | |
if (defaultTargetPlatform == TargetPlatform.iOS) { |
Please also check for other spots for issues like this.
There was a problem hiding this comment.
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');
}
// This tests the case where packageInfo is null | ||
// and default appBundleId gets passed to the [NotificationService.registerToken] method |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
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'); |
There was a problem hiding this comment.
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?
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. |
In this PR, I made the changes to indirect PackageInfo.fromPlatform through a method on ZulipBinding.
Steps I followed :
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.
Override the method in TestZulipBinding: In the TestZulipBinding, override getAppBundleId to return a mock or predefined value for testing.
Refactor the code to use getAppBundleId: Replace the direct calls with the indirection from Zulip Binding class.
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