From c76cbdc7086838f01a8986f8115792aa5876caf0 Mon Sep 17 00:00:00 2001 From: crisnicandrei <62384997+crisnicandrei@users.noreply.github.com> Date: Fri, 22 Sep 2023 12:57:48 +0300 Subject: [PATCH 1/3] PER-9361-Email and phone verification are broken; Changed the way isLoggedIn is handled in the verify component and made sure that keepLoggedIn is not being set to null after phone or mail verification --- .../components/verify/verify.component.ts | 2 +- .../services/account/account.service.ts | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/app/auth/components/verify/verify.component.ts b/src/app/auth/components/verify/verify.component.ts index 40facdfa1..e8ac5a27d 100644 --- a/src/app/auth/components/verify/verify.component.ts +++ b/src/app/auth/components/verify/verify.component.ts @@ -227,6 +227,6 @@ export class VerifyComponent implements OnInit { } private keepLoggedIn(): boolean { - return this.route.snapshot.queryParams.keepLoggedIn === 'true'; + return this.accountService.getAccount().keepLoggedIn; } } diff --git a/src/app/shared/services/account/account.service.ts b/src/app/shared/services/account/account.service.ts index 91f56c1db..52aaaa044 100644 --- a/src/app/shared/services/account/account.service.ts +++ b/src/app/shared/services/account/account.service.ts @@ -447,7 +447,12 @@ export class AccountService { .pipe( map((response: AuthResponse) => { if (response.isSuccessful) { - this.setAccount(response.getAccountVO()); + const keepLoggedIn = this.account.keepLoggedIn; + const account = new AccountVO({ + ...response.getAccountVO(), + keepLoggedIn, + }); + this.setAccount(account); return response; } else { throw response; @@ -463,7 +468,12 @@ export class AccountService { .pipe( map((response: AuthResponse) => { if (response.isSuccessful) { - this.setAccount(response.getAccountVO()); + const keepLoggedIn = this.account.keepLoggedIn; + const account = new AccountVO({ + ...response.getAccountVO(), + keepLoggedIn, + }); + this.setAccount(account); return response; } else { throw response; @@ -550,7 +560,10 @@ export class AccountService { ) .pipe( map((response: AccountVO) => { - const newAccount = response; + const newAccount = new AccountVO({ + ...response, + keepLoggedIn: true, + }); newAccount.isNew = true; this.setAccount(newAccount); this.mixpanel.track('Sign up', { accountId: newAccount.accountId }); From cb47694a2b8c2dea74d2627c81e6d1c4d4c09a9a Mon Sep 17 00:00:00 2001 From: crisnicandrei <62384997+crisnicandrei@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:17:25 +0300 Subject: [PATCH 2/3] PER-9361 Wrote tests to verify if the verifications are succesful. --- .../services/account/account.service.spec.ts | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/app/shared/services/account/account.service.spec.ts b/src/app/shared/services/account/account.service.spec.ts index ef3e66748..a13d2e9c3 100644 --- a/src/app/shared/services/account/account.service.spec.ts +++ b/src/app/shared/services/account/account.service.spec.ts @@ -41,6 +41,32 @@ describe('AccountService', () => { }, get: (account: AccountVO) => Promise.reject({}), }, + auth: { + verify: (account, token, type) => { + return new Observable((observer) => { + observer.next( + new AuthResponse({ + isSuccessful: true, + Results: [ + { + data: [ + { + AccountVO: { + primaryEmail: 'test@permanent.org', + fullName: 'Test User', + emailStatus: 'status.auth.verified', + phoneStatus: 'status.auth.verified', + }, + }, + ], + }, + ], + }) + ); + observer.complete(); + }); + }, + }, }) .mock(Router, { navigate: (route: string[]) => Promise.resolve(true), @@ -99,4 +125,36 @@ describe('AccountService', () => { expect(error).toEqual(expectedError); } }); + + it('should handle successful email verification', async () => { + const { instance } = shallow.createService(); + + const account = new AccountVO({ + primaryEmail: 'test@permanent.org', + fullName: 'Test User', + keepLoggedIn: true, + emailStatus: 'status.auth.unverified', + }); + + instance.setAccount(account); + + await instance.verifyEmail('sampleToken'); + expect(instance.getAccount().emailStatus).toBe('status.auth.verified'); + }); + + it('should handle successful phone verification', async () => { + const { instance } = shallow.createService(); + + const account = new AccountVO({ + primaryEmail: 'test@permanent.org', + fullName: 'Test User', + keepLoggedIn: true, + phoneStatus: 'status.auth.unverified', + }); + + instance.setAccount(account); + + await instance.verifyEmail('sampleToken'); + expect(instance.getAccount().phoneStatus).toBe('status.auth.verified'); + }); }); From 3655391464490bec0e0d36a5c782ffacb4aa43d8 Mon Sep 17 00:00:00 2001 From: crisnicandrei <62384997+crisnicandrei@users.noreply.github.com> Date: Thu, 28 Sep 2023 20:42:43 +0300 Subject: [PATCH 3/3] PER-9361 Added 2 tests to make sure keepLoggedIn is true. --- src/app/shared/services/account/account.service.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/shared/services/account/account.service.spec.ts b/src/app/shared/services/account/account.service.spec.ts index a13d2e9c3..c18d7d9dd 100644 --- a/src/app/shared/services/account/account.service.spec.ts +++ b/src/app/shared/services/account/account.service.spec.ts @@ -140,6 +140,7 @@ describe('AccountService', () => { await instance.verifyEmail('sampleToken'); expect(instance.getAccount().emailStatus).toBe('status.auth.verified'); + expect(instance.getAccount().keepLoggedIn).toBeTrue(); }); it('should handle successful phone verification', async () => { @@ -156,5 +157,6 @@ describe('AccountService', () => { await instance.verifyEmail('sampleToken'); expect(instance.getAccount().phoneStatus).toBe('status.auth.verified'); + expect(instance.getAccount().keepLoggedIn).toBeTrue(); }); });