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

Use push notification ID instead of accountID #13844

Merged
merged 13 commits into from
Feb 22, 2023
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
key: ${{ runner.os }}-jest

- name: Jest tests
run: npx jest --shard=${{ fromJSON(matrix.chunk) }}/${{ strategy.job-total }} --max-workers ${{ steps.cpu-cores.outputs.count }}
run: npx jest --silent --shard=${{ fromJSON(matrix.chunk) }}/${{ strategy.job-total }} --max-workers ${{ steps.cpu-cores.outputs.count }}

shellTests:
if: ${{ github.actor != 'OSBotify' || github.event_name == 'workflow_call' }}
Expand Down
2 changes: 2 additions & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export default {
// Contains the users's block expiration (if they have one)
NVP_BLOCKED_FROM_CONCIERGE: 'private_blockedFromConcierge',

NVP_PRIVATE_PUSH_NOTIFICATION_ID: 'private_pushNotificationID',
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: It isn't clear this ID is coming from Airship. Maybe a comment could help clarify.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still NAB, but bumping this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, missed this. It is not coming from airship.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a comment to explain where it is coming from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


// Plaid data (access tokens, bank accounts ...)
PLAID_DATA: 'plaidData',

Expand Down
16 changes: 4 additions & 12 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,15 @@ Onyx.connect({
* On Android, AuthScreens unmounts when the app is closed with the back button so we manage the
* push subscription when the session changes here.
*/
let previousAccountID;
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (session) => {
const accountID = lodashGet(session, 'accountID');
if (previousAccountID === accountID) {
return;
}

if (accountID) {
PushNotification.register(accountID);
key: ONYXKEYS.NVP_PRIVATE_PUSH_NOTIFICATION_ID,
callback: (notificationID) => {
if (notificationID) {
PushNotification.register(notificationID);
} else {
PushNotification.deregister();
PushNotification.clearNotifications();
}

previousAccountID = accountID;
},
});

Expand Down
8 changes: 6 additions & 2 deletions tests/unit/NetworkTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,14 @@ describe('NetworkTests', () => {

// Third command should be the call to Authenticate
const [thirdCommand] = xhr.mock.calls[2];
expect(thirdCommand).toBe('Authenticate');
expect(thirdCommand).toBe('Log');

// Third command should be the call to Authenticate
const [fourthCommand] = xhr.mock.calls[3];
expect(fourthCommand).toBe('MockCommand');
expect(fourthCommand).toBe('Authenticate');

const [fifthCommand] = xhr.mock.calls[4];
expect(fifthCommand).toBe('MockCommand');

// We are using the new authToken
expect(NetworkStore.getAuthToken()).toBe('newToken');
Expand Down
5 changes: 5 additions & 0 deletions tests/utils/TestHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ function signInWithTestUser(accountID = 1, login = 'test@user.com', password = '
key: ONYXKEYS.BETAS,
value: ['all'],
},
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.NVP_PRIVATE_PUSH_NOTIFICATION_ID,
value: 'randomID',
},
],
jsonCode: 200,
});
Expand Down