Skip to content

Commit

Permalink
Merge pull request #302 from PermanentOrg/PER-9361-email-and-phone-verif
Browse files Browse the repository at this point in the history
PER-9361-Email and phone verification are broken;
  • Loading branch information
crisnicandrei authored Oct 2, 2023
2 parents fe4a97e + 3655391 commit 26e75d3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app/auth/components/verify/verify.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,6 @@ export class VerifyComponent implements OnInit {
}

private keepLoggedIn(): boolean {
return this.route.snapshot.queryParams.keepLoggedIn === 'true';
return this.accountService.getAccount().keepLoggedIn;
}
}
60 changes: 60 additions & 0 deletions src/app/shared/services/account/account.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
fullName: 'Test User',
emailStatus: 'status.auth.verified',
phoneStatus: 'status.auth.verified',
},
},
],
},
],
})
);
observer.complete();
});
},
},
})
.mock(Router, {
navigate: (route: string[]) => Promise.resolve(true),
Expand Down Expand Up @@ -99,4 +125,38 @@ describe('AccountService', () => {
expect(error).toEqual(expectedError);
}
});

it('should handle successful email verification', async () => {
const { instance } = shallow.createService();

const account = new AccountVO({
primaryEmail: '[email protected]',
fullName: 'Test User',
keepLoggedIn: true,
emailStatus: 'status.auth.unverified',
});

instance.setAccount(account);

await instance.verifyEmail('sampleToken');
expect(instance.getAccount().emailStatus).toBe('status.auth.verified');
expect(instance.getAccount().keepLoggedIn).toBeTrue();
});

it('should handle successful phone verification', async () => {
const { instance } = shallow.createService();

const account = new AccountVO({
primaryEmail: '[email protected]',
fullName: 'Test User',
keepLoggedIn: true,
phoneStatus: 'status.auth.unverified',
});

instance.setAccount(account);

await instance.verifyEmail('sampleToken');
expect(instance.getAccount().phoneStatus).toBe('status.auth.verified');
expect(instance.getAccount().keepLoggedIn).toBeTrue();
});
});
19 changes: 16 additions & 3 deletions src/app/shared/services/account/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit 26e75d3

Please sign in to comment.