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

notif: package info indirection #1143

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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.

lib/model/binding.dart Outdated Show resolved Hide resolved
lib/model/binding.dart Outdated Show resolved Hide resolved
lib/notifications/receive.dart Outdated Show resolved Hide resolved
@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 from 2cc9de6 to 3a87065 Compare December 20, 2024 19:43
add test for the appBundleId wrapper
made a group called tokens to check if appBundleId equals 'com.zulip.flutter.test'
made changes to access packageName from the PackageInfo class.
remove getAppBundleId() from Zulip Binding class
Add packageName variable to PackageInfo class
Fixes zulip#407
made packageName accessible to receive.dart file and test files via
(await ZulipBinding.instance.packageInfo)?.packageName ?? "com.zulip.flutter"
@Abhisheksainii Abhisheksainii force-pushed the fix/package-info-indirection branch from 3a87065 to ff11675 Compare December 21, 2024 06:19
@Abhisheksainii
Copy link
Author

@PIG208 kindly review the changes.

@@ -380,6 +380,7 @@ class TestZulipBinding extends ZulipBinding {
Future<void> toggleWakelock({required bool enable}) async {
_wakelockEnabled = enable;
}

Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is unintentional.

@@ -303,10 +303,12 @@ class LinuxDeviceInfo implements BaseDeviceInfo {
class PackageInfo {
Copy link
Member

Choose a reason for hiding this comment

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

binding: add packageName to the packageInfo class in the binding class 
made changes to access packageName from the PackageInfo class.
remove getAppBundleId() from Zulip Binding class
Add packageName variable to PackageInfo class
Fixes #407

The commit claims that getAppBundleId() got removed, but it is not present in the commit itself. For changes that address reviews on a previous revision of the commit, the PR thread is more appropriate.

The commit summary and the "Fixes" line also need to be updated. This commit doesn't fix #407. We should move this line to the next commit where we start using packageName.

For the commit message, changes that one can tell from reading the diffs generally don't need to be reiterated: "made changes to access packageName from the PackageInfo class"
"Add packageName variable to PackageInfo class".

Please review Zulip's commit discipline linked in the README https://github.com/zulip/zulip-flutter?tab=readme-ov-file#submitting-a-pull-request

check(await testBinding.getAppBundleId())
.equals('com.zulip.flutter.test');
}, );
});
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this commit should be dropped as getAppBundleId doesn't exist anymore.

This is one reason that we should include the tests in the same commit that implements the feature tested.

@@ -149,8 +149,8 @@ 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);
// TODO(#407) find actual value live
Copy link
Member

Choose a reason for hiding this comment

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

Since this resolves the TODO, we can remove this line.

@@ -1032,7 +1032,7 @@ void main() {
if (defaultTargetPlatform == TargetPlatform.android) {
checkLastRequestFcm(token: '012abc');
} else {
checkLastRequestApns(token: '012abc', appid: 'com.zulip.flutter');
checkLastRequestApns(token: '012abc', appid:(await testBinding.packageInfo)?.packageName?? 'com.zulip.flutter.test');
Copy link
Member

Choose a reason for hiding this comment

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

The test should encode the clear expectation of what the expected appid is. Let's avoid looking up the value and use a literal string instead.

@@ -1071,7 +1071,7 @@ void main() {
if (defaultTargetPlatform == TargetPlatform.android) {
checkLastRequestFcm(token: '012abc');
} else {
checkLastRequestApns(token: '012abc', appid: 'com.zulip.flutter');
checkLastRequestApns(token: '012abc', appid:(await testBinding.packageInfo)?.packageName?? 'com.zulip.flutter.test');
Copy link
Member

Choose a reason for hiding this comment

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

Same as the other case.

const appBundleId = 'com.zulip.flutter'; // TODO(#407) find actual value live
await addApnsToken(connection, token: token, appid: appBundleId);
// TODO(#407) find actual value live
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.

I think there is an underlying issue if packageInfo is missing, so let's include a // TODO(log) comment here.

Copy link
Member

Choose a reason for hiding this comment

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

This case is interesting so it might worth a test for it. Let's find a way to test when we fallback to this default value, if packageInfo is somehow missing.

@@ -34,7 +34,7 @@ void main() {
group('tokens', () {
test('APNs token registration using correct app bundle ID', () async {
await init();
check(await testBinding.getAppBundleId())
check((await testBinding.packageInfo)?.packageName?? 'com.zulip.flutter.test')
Copy link
Member

Choose a reason for hiding this comment

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

Falling back to com.zulip.flutter.test defeats the purpose of this test. I think we don't expect packageInfo to be missing in this case, right?

@PIG208
Copy link
Member

PIG208 commented Dec 23, 2024

Thanks for the update @Abhisheksainii! Left some comments.

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