Skip to content

Commit 1874b01

Browse files
committed
Check account status, then url parameters
1 parent e5cc3d6 commit 1874b01

File tree

4 files changed

+47
-17
lines changed

4 files changed

+47
-17
lines changed

src/app/auth/components/verify/verify.component.spec.ts

+38-14
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ describe('VerifyComponent', () => {
104104
expect(component.verifyingEmail).toBeTruthy();
105105
expect(component.needsEmail).toBeTruthy();
106106
expect(component.needsPhone).toBeFalsy();
107+
108+
const account = accountService.getAccount();
109+
110+
expect(account.emailNeedsVerification()).toBeTrue();
111+
expect(account.phoneNeedsVerification()).toBeFalse();
107112
});
108113

109114
it('should require only phone verification if only phone unverified', async () => {
@@ -117,30 +122,49 @@ describe('VerifyComponent', () => {
117122

118123
it('should require verification of both if both unverified, and verify email first', async () => {
119124
const unverifiedBothData = require('@root/test/responses/auth.verify.unverifiedBoth.success.json');
120-
await init(unverifiedBothData, { sendEmail: true, sendSms: true });
125+
await init(unverifiedBothData);
121126

122-
expect(component.verifyingEmail).toBeTruthy();
123-
expect(component.needsPhone).toBeTruthy();
124-
expect(component.needsEmail).toBeTruthy();
127+
expect(component.verifyingEmail).toBeTrue();
128+
expect(component.verifyingPhone).toBeFalse();
129+
130+
expect(component.needsEmail).toBeTrue();
131+
expect(component.needsPhone).toBeTrue();
132+
133+
const account = accountService.getAccount();
134+
135+
expect(account.emailNeedsVerification()).toBeTrue();
136+
expect(account.phoneNeedsVerification()).toBeTrue();
125137
});
126138

127139
it('should verify email and then switch to phone verification if needed', async () => {
128140
const unverifiedBothData = require('@root/test/responses/auth.verify.unverifiedBoth.success.json');
129-
await init(unverifiedBothData, { sendEmail: true, sendSms: true });
130141

131-
expect(component.verifyingEmail).toBeTruthy();
132-
expect(component.needsPhone).toBeTruthy();
133-
expect(component.needsEmail).toBeTruthy();
142+
// Remove query params -- let accountService drive both verifications
143+
await init(unverifiedBothData);
144+
145+
expect(component.verifyingEmail).toBeTrue();
146+
expect(component.needsPhone).toBeTrue();
147+
expect(component.needsEmail).toBeTrue();
148+
149+
const account = accountService.getAccount();
150+
151+
expect(account.emailNeedsVerification()).toBeTrue();
152+
expect(account.phoneNeedsVerification()).toBeTrue();
134153

135154
component.onSubmit(component.verifyForm.value).then(() => {
136-
expect(component.waiting).toBeFalsy();
137-
expect(component.verifyingEmail).toBeFalsy();
138-
expect(component.needsEmail).toBeFalsy();
139-
expect(component.needsPhone).toBeTruthy();
140-
expect(component.verifyingPhone).toBeTruthy();
155+
expect(component.waiting).toBeFalse();
156+
expect(component.verifyingEmail).toBeFalse();
157+
expect(component.needsEmail).toBeFalse();
158+
expect(component.needsPhone).toBeTrue();
159+
expect(component.verifyingPhone).toBeTrue();
160+
161+
const updatedAccount = accountService.getAccount();
162+
163+
expect(updatedAccount.emailNeedsVerification()).toBeFalse();
164+
expect(updatedAccount.phoneNeedsVerification()).toBeTrue();
141165
});
142166

143-
expect(component.waiting).toBeTruthy();
167+
expect(component.waiting).toBeTrue();
144168

145169
const verifyEmailResponse = require('@root/test/responses/auth.verify.verifyEmailThenPhone.success.json');
146170
const req = httpMock.expectOne(`${environment.apiUrl}/auth/verify`);

src/app/auth/components/verify/verify.component.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ export class VerifyComponent implements OnInit {
6262
}
6363
const queryParams = route.snapshot.queryParams;
6464

65-
this.needsEmail = queryParams.sendEmail;
66-
this.needsPhone = queryParams.sendSms;
65+
this.needsEmail =
66+
(account.emailNeedsVerification() || queryParams.sendEmail) &&
67+
!queryParams.sendSms;
68+
this.needsPhone = account.phoneNeedsVerification() || queryParams.sendSms;
6769

6870
this.verifyForm = fb.group({
6971
token: [queryParams.token || ''],

src/app/models/account-vo.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ export class AccountVO extends BaseVO {
115115
}
116116

117117
emailNeedsVerification(): boolean {
118-
return this.emailStatus === 'status.auth.unverified';
118+
return (
119+
(this.primaryEmail && !this.emailStatus) ||
120+
this.emailStatus === 'status.auth.unverified'
121+
);
119122
}
120123
}

src/test/responses/auth.login.success.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"AccountVO": {
77
"accountId": 1,
88
"primaryEmail": "[email protected]",
9+
"emailStatus":"type.auth.unverified",
910
"fullName": "Unit Test",
1011
"address": null,
1112
"address2": null,

0 commit comments

Comments
 (0)