1
1
import { noop , render , renderJSON } from '@clerk/shared/testUtils' ;
2
2
import {
3
+ AttributeData ,
3
4
SessionResource ,
4
- SignInStrategyName ,
5
5
#Resource ,
6
+ UserSettingsJSON ,
6
7
} from '@clerk/types' ;
8
+ import { UserSettings } from 'core/resources/internal' ;
7
9
import React from 'react' ;
8
10
9
11
import {
@@ -25,7 +27,7 @@ const mockStartMagicLinkFlow = jest.fn(() => {
25
27
} ,
26
28
} as any as #Resource ) ;
27
29
} ) ;
28
- let mockFirstFactors : SignInStrategyName [ ] ;
30
+ let mockEmailAddressAttribute : Partial < AttributeData > ;
29
31
let mockDisabledStrategies : string [ ] = [ ] ;
30
32
31
33
jest . mock ( 'ui/router/RouteContext' ) ;
@@ -37,15 +39,43 @@ jest.mock('ui/contexts', () => {
37
39
applicationName : 'My test app' ,
38
40
after#Url : 'http://test.host' ,
39
41
} ,
42
+ userSettings : new UserSettings ( {
43
+ attributes : {
44
+ first_name : {
45
+ enabled : true ,
46
+ required : false ,
47
+ } ,
48
+ last_name : {
49
+ enabled : true ,
50
+ required : false ,
51
+ } ,
52
+ password : {
53
+ enabled : true ,
54
+ required : false ,
55
+ } ,
56
+ username : {
57
+ enabled : true ,
58
+ required : false ,
59
+ } ,
60
+ email_address : mockEmailAddressAttribute ,
61
+ } ,
62
+ social : {
63
+ oauth_google : {
64
+ enabled : true ,
65
+ required : false ,
66
+ authenticatable : false ,
67
+ strategy : 'oauth_google' ,
68
+ } ,
69
+ oauth_facebook : {
70
+ enabled : true ,
71
+ required : false ,
72
+ authenticatable : false ,
73
+ strategy : 'oauth_facebook' ,
74
+ } ,
75
+ } ,
76
+ } as unknown as UserSettingsJSON ) ,
40
77
authConfig : {
41
- username : 'on' ,
42
- firstName : 'required' ,
43
- lastName : 'required' ,
44
- password : 'required' ,
45
- firstFactors : mockFirstFactors ,
46
- identificationRequirements : [
47
- [ 'email_address' , 'phone_address' , 'oauth_google' , 'oauth_facebook' ] ,
48
- ] ,
78
+ singleSessionMode : false ,
49
79
} ,
50
80
} ) ) ,
51
81
useCoreSession : ( ) => {
@@ -105,20 +135,33 @@ describe('<#Verify/>', () => {
105
135
} ) ;
106
136
107
137
describe ( 'verify email address' , ( ) => {
108
- it ( 'renders the # verification form' , async ( ) => {
109
- mockFirstFactors = [ 'email_code' , 'phone_code' , 'password' ] ;
138
+ it ( 'renders the # verification form' , ( ) => {
139
+ mockEmailAddressAttribute = {
140
+ enabled : true ,
141
+ first_factors : [ 'email_code' ] ,
142
+ verifications : [ 'email_code' ] ,
143
+ } ;
144
+ // mockFirstFactors = ['email_code', 'phone_code', 'password'];
110
145
const tree = renderJSON ( < #VerifyEmailAddress /> ) ;
111
146
expect ( tree ) . toMatchSnapshot ( ) ;
112
147
} ) ;
113
148
114
- it ( 'renders the # verification form but prefers email_link if exists' , async ( ) => {
115
- mockFirstFactors = [ 'email_code' , 'phone_code' , 'password' , 'email_link' ] ;
149
+ it ( 'renders the # verification form but prefers email_link if exists' , ( ) => {
150
+ mockEmailAddressAttribute = {
151
+ enabled : true ,
152
+ first_factors : [ 'email_link' ] ,
153
+ verifications : [ 'email_link' ] ,
154
+ } ;
116
155
const tree = renderJSON ( < #VerifyEmailAddress /> ) ;
117
156
expect ( tree ) . toMatchSnapshot ( ) ;
118
157
} ) ;
119
158
120
- it ( 'can skip disabled verification strategies' , async ( ) => {
121
- mockFirstFactors = [ 'email_code' , 'phone_code' , 'password' , 'email_link' ] ;
159
+ it ( 'can skip disabled verification strategies' , ( ) => {
160
+ mockEmailAddressAttribute = {
161
+ enabled : true ,
162
+ first_factors : [ 'email_link' ] ,
163
+ verifications : [ 'email_link' ] ,
164
+ } ;
122
165
mockDisabledStrategies = [ 'email_link' ] ;
123
166
const { container } = render ( < #VerifyEmailAddress /> ) ;
124
167
expect ( container . querySelector ( '.cl-otp-input' ) ) . not . toBeNull ( ) ;
@@ -131,7 +174,7 @@ describe('<#Verify/>', () => {
131
174
} ) ;
132
175
133
176
describe ( 'verify phone number' , ( ) => {
134
- it ( 'renders the # verification form' , async ( ) => {
177
+ it ( 'renders the # verification form' , ( ) => {
135
178
const tree = renderJSON ( < #VerifyPhoneNumber /> ) ;
136
179
expect ( tree ) . toMatchSnapshot ( ) ;
137
180
} ) ;
0 commit comments