Skip to content

Commit 67ab92d

Browse files
committed
Retrieve all methods using api call
1 parent b6b29db commit 67ab92d

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/app/core/components/two-factor-auth/two-factor-auth.component.spec.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,29 @@ describe('TwoFactorAuthComponent', () => {
171171
expect(codeContainer.length).toBe(0);
172172
});
173173

174-
it('should call showError when submitRemoveMethod fails', async () => {
174+
it('should retrieve all the methods after a method has been deleted', async () => {
175175
const { instance } = await shallow.render();
176-
messageShown = false;
177-
178-
spyOn(mockApiService.idpuser, 'disableTwoFactor').and.returnValue(
179-
Promise.reject(new Error('API Error')),
180-
);
181176

177+
instance.methods = [
178+
{ methodId: 'email', method: 'email', value: 'janedoe@example.com' },
179+
];
182180
instance.selectedMethodToDelete = {
183181
methodId: 'email',
184182
method: 'email',
185-
value: 'user@example.com',
183+
value: 'janedoe@example.com',
186184
};
187-
instance.form.get('code').setValue('123456');
185+
186+
spyOn(mockApiService.idpuser, 'disableTwoFactor').and.returnValue(
187+
Promise.resolve(),
188+
);
189+
spyOn(mockApiService.idpuser, 'getTwoFactorMethods').and.returnValue(
190+
Promise.resolve([
191+
{ methodId: 'sms', method: 'sms', value: '(123) 456-7890' },
192+
]),
193+
);
188194

189195
await instance.submitRemoveMethod();
190196

191-
expect(messageShown).toBeTrue();
197+
expect(mockApiService.idpuser.getTwoFactorMethods).toHaveBeenCalled();
192198
});
193199
});

src/app/core/components/two-factor-auth/two-factor-auth.component.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,9 @@ export class TwoFactorAuthComponent implements OnInit {
170170
this.selectedMethodToDelete.methodId,
171171
this.form.get('code').value,
172172
);
173-
174-
this.methods = this.methods.filter(
175-
(m) => m.methodId !== this.selectedMethodToDelete.methodId,
176-
);
177173
} catch (error) {
178-
this.message.showError({
179-
message: 'Something went wrong while attempting to remove the method',
180-
});
181174
} finally {
175+
this.methods = await this.api.idpuser.getTwoFactorMethods();
182176
this.selectedMethodToDelete = null;
183177
this.codeSent = false;
184178
this.method = null;

0 commit comments

Comments
 (0)