1
1
import { test , expect } from '@playwright/test' ;
2
2
import models from '../src/modules/sequelize/models' ;
3
3
import { config } from '../src/config' ;
4
- import { changeOTP , fillOTP , initURL , clientId } from './util' ;
4
+ import { errors } from '../src/utils/shared'
5
+ import { changeOTP , fillOTP , initURL , clientId , redirectURI } from './util' ;
5
6
6
7
const otpModel = models . get ( 'Otp' ) ;
7
8
const eventModel = models . get ( 'Event' ) ;
@@ -22,8 +23,7 @@ test('OTP Validations', async ({ page }, testInfo) => {
22
23
await expect ( page . getByRole ( 'heading' ) ) . toMatchAriaSnapshot ( `- heading "Enter your verification code" [level=2]` ) ;
23
24
24
25
await page . getByRole ( 'textbox' , { name : 'Digit 1' } ) . fill ( 'a' ) ;
25
- await expect ( page . locator ( '#otp-error' ) ) . toMatchAriaSnapshot ( `- text: OTP Must only include digits [0-9].` ) ;
26
-
26
+ await expect ( page . locator ( '#otp-error' ) ) . toHaveText ( errors . OTP_TYPES ) ;
27
27
const currentOtp = await otpModel
28
28
. findOne ( { where : { email : `${ testInfo . project . name } @b.com` , active : true } } )
29
29
. then ( ( res ) => res . otp ) ;
@@ -36,6 +36,35 @@ test('OTP Validations', async ({ page }, testInfo) => {
36
36
) ;
37
37
} ) ;
38
38
39
+ test ( 'OTP submits when all digits are filled regardless of order' , async ( { page } , testInfo ) => {
40
+ await page . goto ( initURL ) ;
41
+
42
+ // Enter email and go to OTP page
43
+ await page . getByRole ( 'textbox' , { name : 'Email' } ) . fill ( `${ testInfo . project . name } @b.com` ) ;
44
+ await page . getByRole ( 'button' , { name : 'Continue' } ) . click ( ) ;
45
+ await page . waitForURL ( '**/otp' ) ;
46
+ await expect ( page . getByRole ( 'heading' ) ) . toMatchAriaSnapshot ( `- heading "Enter your verification code" [level=2]` ) ;
47
+
48
+ const currentOtp = await otpModel
49
+ . findOne ( { where : { email : `${ testInfo . project . name } @b.com` , active : true } } )
50
+ . then ( ( res ) => res . otp ) ;
51
+
52
+ // Fill the first 4 digits
53
+ for ( let i = 0 ; i < 4 ; i ++ ) {
54
+ await page . getByRole ( 'textbox' , { name : `Digit ${ i + 1 } ` } ) . fill ( currentOtp [ i ] ) ;
55
+ }
56
+ // Fill the 6th digit
57
+ await page . getByRole ( 'textbox' , { name : "Digit 6" } ) . fill ( currentOtp [ 5 ] ) ;
58
+
59
+ // Fill the 5th digit.
60
+ await page . getByRole ( 'textbox' , { name : "Digit 5" } ) . fill ( currentOtp [ 4 ] ) ;
61
+
62
+ // Submission should run and send to the redirect
63
+ await page . waitForRequest ( ( req ) => {
64
+ return req . url ( ) . startsWith ( redirectURI ) ;
65
+ } ) ;
66
+ } ) ;
67
+
39
68
test ( 'OTP Resend Code Countdown' , async ( { page } , testInfo ) => {
40
69
await page . goto ( initURL ) ;
41
70
0 commit comments