|
| 1 | +import { parseError } from '@clerk/shared/error'; |
1 | 2 | import type { SignInResource } from '@clerk/types';
|
2 | 3 | import { describe, it, jest } from '@jest/globals';
|
3 | 4 | import { waitFor } from '@testing-library/dom';
|
@@ -193,6 +194,38 @@ describe('SignInFactorOne', () => {
|
193 | 194 | await waitFor(() => expect(screen.getByText('Incorrect Password')).toBeDefined());
|
194 | 195 | });
|
195 | 196 | });
|
| 197 | + |
| 198 | + it('redirects back to sign-in if the user is locked', async () => { |
| 199 | + const { wrapper, fixtures } = await createFixtures(f => { |
| 200 | + f.withEmailAddress(); |
| 201 | + f.withPassword(); |
| 202 | + f.withPreferredSignInStrategy({ strategy: 'password' }); |
| 203 | + f.startSignInWithPhoneNumber({ supportPassword: true }); |
| 204 | + }); |
| 205 | + fixtures.signIn.prepareFirstFactor.mockReturnValueOnce(Promise.resolve({} as SignInResource)); |
| 206 | + |
| 207 | + const errJSON = { |
| 208 | + code: 'user_locked', |
| 209 | + long_message: 'Your account is locked. Please try again after 1 hour.', |
| 210 | + message: 'Account locked', |
| 211 | + meta: { duration_in_seconds: 3600 }, |
| 212 | + }; |
| 213 | + |
| 214 | + fixtures.signIn.attemptFirstFactor.mockRejectedValueOnce( |
| 215 | + new ClerkAPIResponseError('Error', { |
| 216 | + data: [errJSON], |
| 217 | + status: 422, |
| 218 | + }), |
| 219 | + ); |
| 220 | + await runFakeTimers(async () => { |
| 221 | + const { userEvent } = render(<SignInFactorOne />, { wrapper }); |
| 222 | + await userEvent.type(screen.getByLabelText('Password'), '123456'); |
| 223 | + await userEvent.click(screen.getByText('Continue')); |
| 224 | + await waitFor(() => { |
| 225 | + expect(fixtures.clerk.__internal_navigateWithError).toHaveBeenCalledWith('..', parseError(errJSON)); |
| 226 | + }); |
| 227 | + }); |
| 228 | + }); |
196 | 229 | });
|
197 | 230 |
|
198 | 231 | describe('Forgot Password', () => {
|
@@ -405,6 +438,35 @@ describe('SignInFactorOne', () => {
|
405 | 438 | await waitFor(() => expect(screen.getByText('Incorrect code')).toBeDefined());
|
406 | 439 | });
|
407 | 440 | });
|
| 441 | + |
| 442 | + it('redirects back to sign-in if the user is locked', async () => { |
| 443 | + const { wrapper, fixtures } = await createFixtures(f => { |
| 444 | + f.withEmailAddress(); |
| 445 | + f.withPreferredSignInStrategy({ strategy: 'otp' }); |
| 446 | + f.startSignInWithPhoneNumber({ supportPhoneCode: true, supportPassword: false }); |
| 447 | + }); |
| 448 | + fixtures.signIn.prepareFirstFactor.mockReturnValueOnce(Promise.resolve({} as SignInResource)); |
| 449 | + |
| 450 | + const errJSON = { |
| 451 | + code: 'user_locked', |
| 452 | + long_message: 'Your account is locked. Please try again after 2 hours.', |
| 453 | + message: 'Account locked', |
| 454 | + meta: { duration_in_seconds: 7200 }, |
| 455 | + }; |
| 456 | + |
| 457 | + fixtures.signIn.attemptFirstFactor.mockRejectedValueOnce( |
| 458 | + new ClerkAPIResponseError('Error', { |
| 459 | + data: [errJSON], |
| 460 | + status: 422, |
| 461 | + }), |
| 462 | + ); |
| 463 | + |
| 464 | + await runFakeTimers(async () => { |
| 465 | + const { userEvent } = render(<SignInFactorOne />, { wrapper }); |
| 466 | + await userEvent.type(screen.getByLabelText(/Enter verification code/i), '123456'); |
| 467 | + expect(fixtures.clerk.__internal_navigateWithError).toHaveBeenCalledWith('..', parseError(errJSON)); |
| 468 | + }); |
| 469 | + }); |
408 | 470 | });
|
409 | 471 |
|
410 | 472 | describe('Phone Code', () => {
|
@@ -484,6 +546,36 @@ describe('SignInFactorOne', () => {
|
484 | 546 | await waitFor(() => expect(screen.getByText('Incorrect phone code')).toBeDefined());
|
485 | 547 | });
|
486 | 548 | });
|
| 549 | + |
| 550 | + it('redirects back to sign-in if the user is locked', async () => { |
| 551 | + const { wrapper, fixtures } = await createFixtures(f => { |
| 552 | + f.withPhoneNumber(); |
| 553 | + f.withPreferredSignInStrategy({ strategy: 'otp' }); |
| 554 | + f.startSignInWithPhoneNumber({ supportPhoneCode: true, supportPassword: false }); |
| 555 | + }); |
| 556 | + fixtures.signIn.prepareFirstFactor.mockReturnValueOnce(Promise.resolve({} as SignInResource)); |
| 557 | + |
| 558 | + const errJSON = { |
| 559 | + code: 'user_locked', |
| 560 | + long_message: 'Your account is locked. Please contact support for more information.', |
| 561 | + message: 'Account locked', |
| 562 | + }; |
| 563 | + |
| 564 | + fixtures.signIn.attemptFirstFactor.mockRejectedValueOnce( |
| 565 | + new ClerkAPIResponseError('Error', { |
| 566 | + data: [errJSON], |
| 567 | + status: 422, |
| 568 | + }), |
| 569 | + ); |
| 570 | + |
| 571 | + await runFakeTimers(async () => { |
| 572 | + const { userEvent } = render(<SignInFactorOne />, { wrapper }); |
| 573 | + await userEvent.type(screen.getByLabelText(/Enter verification code/i), '123456'); |
| 574 | + await waitFor(() => { |
| 575 | + expect(fixtures.clerk.__internal_navigateWithError).toHaveBeenCalledWith('..', parseError(errJSON)); |
| 576 | + }); |
| 577 | + }); |
| 578 | + }); |
487 | 579 | });
|
488 | 580 | });
|
489 | 581 |
|
|
0 commit comments