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

PER-9361-Email and phone verification are broken; #302

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
expect(instance.getAccount().emailStatus).toBe('status.auth.verified');
expect(instance.getAccount().emailStatus).toBe('status.auth.verified');
expect(instance.getAccount().keepLoggedIn).toBeTrue();

Let's add a check for the keepLoggedIn behavior since that's what this particular ticket is all about. These tests otherwise just check for email/phone verification, and so pass even when copied over to the main branch. I'd like to see these tests fail if we run them if the specific bug addressed in this ticket isn't fixed, if that makes sense.

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');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
expect(instance.getAccount().phoneStatus).toBe('status.auth.verified');
expect(instance.getAccount().phoneStatus).toBe('status.auth.verified');
expect(instance.getAccount().keepLoggedIn).toBeTrue();

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
Loading