@@ -160,4 +160,62 @@ describe("QrCodeAuth", function () {
160
160
} ) ;
161
161
} ) ;
162
162
} ) ;
163
+
164
+ describe ( "GET call for fetching user device info" , function ( ) {
165
+ let userId = "" ;
166
+ let userDeviceInfoData ;
167
+ beforeEach ( async function ( ) {
168
+ userId = await addUser ( user ) ;
169
+ userDeviceInfoData = {
170
+ ...userDeviceInfoDataArray [ 0 ] ,
171
+ user_id : userId ,
172
+ authorization_status : "NOT_INIT" ,
173
+ access_token : "ACCESS_TOKEN" ,
174
+ } ;
175
+ } ) ;
176
+ afterEach ( async function ( ) {
177
+ await cleanDb ( ) ;
178
+ } ) ;
179
+
180
+ it ( "should successfully fetch the user device info" , function ( done ) {
181
+ qrCodeAuthModel . storeUserDeviceInfo ( userDeviceInfoData ) . then ( ( response ) => {
182
+ chai
183
+ . request ( app )
184
+ . get ( `/auth/qr-code-auth?device_id=${ response . userDeviceInfoData . device_id } ` )
185
+ . end ( ( err , res ) => {
186
+ if ( err ) {
187
+ return done ( err ) ;
188
+ }
189
+ expect ( res ) . to . have . status ( 200 ) ;
190
+ expect ( res . body ) . to . be . a ( "object" ) ;
191
+ expect ( res . body . data . user_id ) . to . be . a ( "string" ) ;
192
+ expect ( res . body . data . device_info ) . to . be . a ( "string" ) ;
193
+ expect ( res . body . data . device_id ) . to . be . a ( "string" ) ;
194
+ expect ( res . body . data . authorization_status ) . to . be . a ( "string" ) ;
195
+ expect ( res . body . data . access_token ) . to . be . a ( "string" ) ;
196
+ expect ( res . body . message ) . to . equal ( `Authentication document retrieved successfully.` ) ;
197
+
198
+ return done ( ) ;
199
+ } ) ;
200
+ } ) ;
201
+ } ) ;
202
+
203
+ it ( "should fail with 404, when the document is not found" , function ( done ) {
204
+ chai
205
+ . request ( app )
206
+ . get ( `/auth/qr-code-auth?device_id=${ userDeviceInfoData . device_id } ` )
207
+ . end ( ( err , res ) => {
208
+ if ( err ) {
209
+ return done ( err ) ;
210
+ }
211
+
212
+ expect ( res ) . to . have . status ( 404 ) ;
213
+ expect ( res . body ) . to . be . a ( "object" ) ;
214
+ expect ( res . body . message ) . to . equal ( `User with id ${ userDeviceInfoData . device_id } does not exist.` ) ;
215
+ expect ( res . body . error ) . to . equal ( "Not Found" ) ;
216
+
217
+ return done ( ) ;
218
+ } ) ;
219
+ } ) ;
220
+ } ) ;
163
221
} ) ;
0 commit comments