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

test: explicitly assert for Log.error calls in registerForPush #1206

Merged
merged 3 commits into from
Nov 18, 2024

Conversation

sherwinski
Copy link
Contributor

@sherwinski sherwinski commented Nov 14, 2024

Description

1 Line Summary

Explicitly tests for an error in the registerForPush test.

Details

When running current tests, the following error is emitted:

  console.error
    PushPermissionNotGrantedError: The user dismissed the permission prompt.
        at SubscriptionManager.subscribeFcmFromPage (/Website-SDK/src/shared/managers/SubscriptionManager.ts:461:17)
        at SubscriptionManager.subscribe (/Website-SDK/src/shared/managers/SubscriptionManager.ts:162:13)
        at Function.internalRegisterForPush (/Website-SDK/src/shared/helpers/SubscriptionHelper.ts:30:35)
        at Function.registerForPush (/Website-SDK/src/shared/helpers/SubscriptionHelper.ts:20:12)
        at Function.registerForPushNotifications (/Website-SDK/src/shared/helpers/InitHelper.ts:104:5)
        at PromptsManager.internalShowNativePrompt (/Website-SDK/src/page/managers/PromptsManager.ts:188:5)
        at NotificationsNamespace.requestPermission (/Website-SDK/src/onesignal/NotificationsNamespace.ts:142:5)
        at PushSubscriptionNamespace.optIn (/Website-SDK/src/onesignal/PushSubscriptionNamespace.ts:96:7)
        at Object.<anonymous> (/Website-SDK/__test__/unit/push/registerForPush.test.ts:33:5) {
      reason: 1
    }

This change adds an assertion since the error is part of the test's expected behavior.

Even though the error occurs, the tests still pass. For that reason, I assumed it's not part of the test's expected behavior. Please feel free to correct me if my understanding there is wrong.

Note: If needed we can add something like expect(Log.error).toHaveBeenCalled() to ensure that we are testing for the existence of the error.

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

Checklist

  • All the automated tests pass or I explained why that is not possible
  • I have personally tested this on my machine or explained why that is not possible
  • I have included test coverage for these changes or explained why they are not needed

Programming Checklist
Interfaces:

  • Don't use default export
  • New interfaces are in model files

Functions:

  • Don't use default export
  • All function signatures have return types
  • Helpers should not access any data but rather be given the data to operate on.

Typescript:

  • No Typescript warnings
  • Avoid silencing null/undefined warnings with the exclamation point

Other:

  • Iteration: refrain from using elem of array syntax. Prefer forEach or use map
  • Avoid using global OneSignal accessor for context if possible. Instead, we can pass it to function/constructor so that we don't call OneSignal.context

Screenshots

Info

Checklist

  • I have included screenshots/recordings of the intended results or explained why they are not needed

Related Tickets



This change is Reviewable

@sherwinski sherwinski requested a review from jkasten2 November 14, 2024 22:13
@shepherd-l
Copy link
Contributor

Even though the error occurs, the tests still pass. For that reason, I assumed it's not part of the test's expected behavior. Please feel free to correct me if my understanding there is wrong.

I was also unsure at first but I think it's part of the test's expected behaviour as discussed here: #1192 (review)

Note: If needed we can add something like expect(Log.error).toHaveBeenCalled() to ensure that we are testing for the existence of the error.

Good idea, this makes sense to do inorder to avoid confusion

- Replace manual Log.error spy with Jest mock
- Add complete mock implementation for Log methods (error, warn, info, debug)
- Add explicit assertions for Log.error calls
@sherwinski sherwinski changed the title test: suppress PushPermissionNotGrantedError test: explicitly assert for Log.error calls in registerForPush Nov 18, 2024
Copy link
Contributor

@shepherd-l shepherd-l left a comment

Choose a reason for hiding this comment

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

Lgtm!

@sherwinski sherwinski merged commit 41a141b into main Nov 18, 2024
4 checks passed
@sherwinski sherwinski deleted the silence-push-error branch November 18, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants