@@ -94,7 +94,11 @@ describe("Middleware | Validators | User", function () {
9494 describe ( "Create user validator for updateUser" , function ( ) {
9595 it ( "lets the request pass to next" , async function ( ) {
9696 const req = {
97- body : userData [ 1 ] ,
97+ body : {
98+ ...userData [ 1 ] ,
99+ first_name : "Ankush" ,
100+ last_name : "Dharkar" ,
101+ } ,
98102 } ;
99103
100104 const res = { } ;
@@ -310,6 +314,62 @@ describe("Middleware | Validators | User", function () {
310314
311315 expect ( nextSpy . calledOnce ) . to . be . equal ( false ) ;
312316 } ) ;
317+
318+ it ( "converts first_name to lowercase before passing to next" , async function ( ) {
319+ const req = {
320+ body : {
321+ first_name : "Ankush" ,
322+ last_name : "Dharkar" ,
323+ } ,
324+ } ;
325+
326+ const res = { } ;
327+ const next = sinon . spy ( ) ;
328+ await updateUser ( req , res , next ) ;
329+
330+ expect ( req . body . first_name ) . to . be . equal ( "ankush" ) ;
331+ expect ( req . body . last_name ) . to . be . equal ( "dharkar" ) ;
332+ expect ( next . calledOnce ) . to . be . equal ( true ) ;
333+ } ) ;
334+
335+ it ( "converts last_name to lowercase before passing to next" , async function ( ) {
336+ const req = {
337+ body : {
338+ first_name : "ANKUSH" ,
339+ last_name : "DHARKAR" ,
340+ } ,
341+ } ;
342+
343+ const res = { } ;
344+ const next = sinon . spy ( ) ;
345+ await updateUser ( req , res , next ) ;
346+
347+ expect ( req . body . first_name ) . to . be . equal ( "ankush" ) ;
348+ expect ( req . body . last_name ) . to . be . equal ( "dharkar" ) ;
349+ expect ( next . calledOnce ) . to . be . equal ( true ) ;
350+ } ) ;
351+
352+ it ( "stops the propagation of the next if first_name and last_name are not strings" , async function ( ) {
353+ const req = {
354+ body : {
355+ first_name : 12345 ,
356+ last_name : true ,
357+ } ,
358+ } ;
359+
360+ const res = {
361+ boom : {
362+ badRequest : ( ) => { } ,
363+ } ,
364+ } ;
365+
366+ const nextSpy = sinon . spy ( ) ;
367+ await updateUser ( req , res , nextSpy ) . catch ( ( err ) => {
368+ expect ( err ) . to . be . an . instanceOf ( Error ) ;
369+ } ) ;
370+
371+ expect ( nextSpy . calledOnce ) . to . be . equal ( false ) ;
372+ } ) ;
313373 } ) ;
314374
315375 describe ( "Test the update Self Validator for disabled_roles property" , function ( ) {
0 commit comments