@@ -10,6 +10,27 @@ describe('RequireNewPassword test', () => {
10
10
11
11
wrapper . setProps ( {
12
12
authState : 'requireNewPassword' ,
13
+ authData : {
14
+ challengeParam : {
15
+ requiredAttributes : [ ]
16
+ }
17
+ } ,
18
+ hide : false
19
+ } ) ;
20
+
21
+ expect ( wrapper ) . toMatchSnapshot ( ) ;
22
+ } ) ;
23
+
24
+ test ( 'render correctly with required attributes' , ( ) => {
25
+ const wrapper = shallow ( < RequireNewPassword /> ) ;
26
+
27
+ wrapper . setProps ( {
28
+ authState : 'requireNewPassword' ,
29
+ authData : {
30
+ challengeParam : {
31
+ requiredAttributes : [ 'given_name' , 'family_name' ]
32
+ }
33
+ } ,
13
34
hide : false
14
35
} ) ;
15
36
@@ -47,6 +68,11 @@ describe('RequireNewPassword test', () => {
47
68
48
69
wrapper . setProps ( {
49
70
authState : 'requireNewPassword' ,
71
+ authData : {
72
+ challengeParam : {
73
+ requiredAttributes : [ ]
74
+ }
75
+ } ,
50
76
hide : false
51
77
} ) ;
52
78
@@ -64,6 +90,11 @@ describe('RequireNewPassword test', () => {
64
90
65
91
wrapper . setProps ( {
66
92
authState : 'requireNewPassword' ,
93
+ authData : {
94
+ challengeParam : {
95
+ requiredAttributes : [ ]
96
+ }
97
+ } ,
67
98
hide : false
68
99
} ) ;
69
100
@@ -80,7 +111,7 @@ describe('RequireNewPassword test', () => {
80
111
const props = {
81
112
authData : {
82
113
challengeParam : {
83
- requiredAttributes : 'requiredAttributes'
114
+ requiredAttributes : [ ]
84
115
}
85
116
}
86
117
}
@@ -102,9 +133,9 @@ describe('RequireNewPassword test', () => {
102
133
103
134
await requireNewPassword . change ( ) ;
104
135
105
- expect ( spyon ) . toBeCalledWith ( { "challengeParam" : { "requiredAttributes" : "requiredAttributes" } } ,
136
+ expect ( spyon ) . toBeCalledWith ( { "challengeParam" : { "requiredAttributes" : [ ] } } ,
106
137
'password' ,
107
- 'requiredAttributes' ) ;
138
+ { } ) ;
108
139
109
140
expect ( spyon2 ) . toBeCalledWith ( 'user' ) ;
110
141
spyon . mockClear ( ) ;
@@ -114,7 +145,7 @@ describe('RequireNewPassword test', () => {
114
145
const props = {
115
146
authData : {
116
147
challengeParam : {
117
- requiredAttributes : 'requiredAttributes'
148
+ requiredAttributes : [ ]
118
149
}
119
150
}
120
151
}
@@ -133,14 +164,14 @@ describe('RequireNewPassword test', () => {
133
164
134
165
wrapper . setProps ( props ) ;
135
166
requireNewPassword . inputs = {
136
- password : 'password'
167
+ password : 'password' ,
137
168
}
138
169
139
170
await requireNewPassword . change ( ) ;
140
171
141
- expect ( spyon ) . toBeCalledWith ( { "challengeParam" : { "requiredAttributes" : "requiredAttributes" } } ,
172
+ expect ( spyon ) . toBeCalledWith ( { "challengeParam" : { "requiredAttributes" : [ ] } } ,
142
173
'password' ,
143
- 'requiredAttributes' ) ;
174
+ { } ) ;
144
175
145
176
expect ( spyon2 ) . toBeCalledWith ( 'confirmSignIn' , { challengeName : 'SMS_MFA' } ) ;
146
177
spyon . mockClear ( ) ;
@@ -150,7 +181,7 @@ describe('RequireNewPassword test', () => {
150
181
const props = {
151
182
authData : {
152
183
challengeParam : {
153
- requiredAttributes : 'requiredAttributes'
184
+ requiredAttributes : [ ]
154
185
}
155
186
}
156
187
}
@@ -174,9 +205,9 @@ describe('RequireNewPassword test', () => {
174
205
175
206
await requireNewPassword . change ( ) ;
176
207
177
- expect ( spyon ) . toBeCalledWith ( { "challengeParam" : { "requiredAttributes" : "requiredAttributes" } } ,
208
+ expect ( spyon ) . toBeCalledWith ( { "challengeParam" : { "requiredAttributes" : [ ] } } ,
178
209
'password' ,
179
- 'requiredAttributes' ) ;
210
+ { } ) ;
180
211
181
212
expect ( spyon2 ) . toBeCalledWith ( 'TOTPSetup' , { challengeName : 'MFA_SETUP' } ) ;
182
213
spyon . mockClear ( ) ;
@@ -211,6 +242,42 @@ describe('RequireNewPassword test', () => {
211
242
spyon . mockClear ( ) ;
212
243
spyon2 . mockClear ( ) ;
213
244
} ) ;
245
+
246
+ test ( 'requiredAttributes test' , async ( ) => {
247
+ const props = {
248
+ authData : {
249
+ challengeParam : {
250
+ requiredAttributes : [ 'given_name' , 'family_name' ]
251
+ }
252
+ }
253
+ }
254
+
255
+ const spyon = jest . spyOn ( Auth , 'completeNewPassword' ) . mockImplementationOnce ( ( ) => {
256
+ return new Promise ( ( res , rej ) => {
257
+ res ( 'user' ) ;
258
+ } ) ;
259
+ } ) ;
260
+ const spyon2 = jest . spyOn ( RequireNewPassword . prototype , 'checkContact' ) . mockImplementationOnce ( ( ) => { return ; } ) ;
261
+
262
+ const wrapper = shallow ( < RequireNewPassword /> ) ;
263
+ const requireNewPassword = wrapper . instance ( ) ;
264
+
265
+ wrapper . setProps ( props ) ;
266
+ requireNewPassword . inputs = {
267
+ password : 'password' ,
268
+ given_name : 'Max' ,
269
+ family_name : 'Power'
270
+ }
271
+
272
+ await requireNewPassword . change ( ) ;
273
+
274
+ expect ( spyon ) . toBeCalledWith ( { "challengeParam" : { "requiredAttributes" : [ 'given_name' , 'family_name' ] } } ,
275
+ 'password' ,
276
+ { given_name : 'Max' , family_name : 'Power' } ) ;
277
+
278
+ expect ( spyon2 ) . toBeCalledWith ( 'user' ) ;
279
+ spyon . mockClear ( ) ;
280
+ } ) ;
214
281
} ) ;
215
282
216
283
describe ( 'checkContact test' , ( ) => {
0 commit comments