@@ -624,97 +624,129 @@ describe("UserDal", () => {
624624 } ) ;
625625 } ) ;
626626
627- it ( "updateProfile should appropriately handle multiple profile updates" , async ( ) => {
628- const uid = new ObjectId ( ) . toHexString ( ) ;
629- await UserDAL . addUser ( "test name" , "test email" , uid ) ;
627+ describe ( "updateProfile" , ( ) => {
628+ it ( "updateProfile should appropriately handle multiple profile updates" , async ( ) => {
629+ const uid = new ObjectId ( ) . toHexString ( ) ;
630+ await UserDAL . addUser ( "test name" , "test email" , uid ) ;
630631
631- await UserDAL . updateProfile (
632- uid ,
633- {
632+ await UserDAL . updateProfile (
633+ uid ,
634+ {
635+ bio : "test bio" ,
636+ } ,
637+ {
638+ badges : [ ] ,
639+ }
640+ ) ;
641+
642+ const user = await UserDAL . getUser ( uid , "test add result filters" ) ;
643+ expect ( user . profileDetails ) . toStrictEqual ( {
634644 bio : "test bio" ,
635- } ,
636- {
645+ } ) ;
646+ expect ( user . inventory ) . toStrictEqual ( {
637647 badges : [ ] ,
638- }
639- ) ;
648+ } ) ;
640649
641- const user = await UserDAL . getUser ( uid , "test add result filters" ) ;
642- expect ( user . profileDetails ) . toStrictEqual ( {
643- bio : "test bio" ,
644- } ) ;
645- expect ( user . inventory ) . toStrictEqual ( {
646- badges : [ ] ,
647- } ) ;
650+ await UserDAL . updateProfile (
651+ uid ,
652+ {
653+ keyboard : "test keyboard" ,
654+ socialProfiles : {
655+ twitter : "test twitter" ,
656+ } ,
657+ } ,
658+ {
659+ badges : [
660+ {
661+ id : 1 ,
662+ selected : true ,
663+ } ,
664+ ] ,
665+ }
666+ ) ;
648667
649- await UserDAL . updateProfile (
650- uid ,
651- {
668+ const updatedUser = await UserDAL . getUser ( uid , "test add result filters" ) ;
669+ expect ( updatedUser . profileDetails ) . toStrictEqual ( {
670+ bio : "test bio" ,
652671 keyboard : "test keyboard" ,
653672 socialProfiles : {
654673 twitter : "test twitter" ,
655674 } ,
656- } ,
657- {
675+ } ) ;
676+ expect ( updatedUser . inventory ) . toStrictEqual ( {
658677 badges : [
659678 {
660679 id : 1 ,
661680 selected : true ,
662681 } ,
663682 ] ,
664- }
665- ) ;
683+ } ) ;
666684
667- const updatedUser = await UserDAL . getUser ( uid , "test add result filters" ) ;
668- expect ( updatedUser . profileDetails ) . toStrictEqual ( {
669- bio : "test bio" ,
670- keyboard : "test keyboard" ,
671- socialProfiles : {
672- twitter : "test twitter" ,
673- } ,
674- } ) ;
675- expect ( updatedUser . inventory ) . toStrictEqual ( {
676- badges : [
685+ await UserDAL . updateProfile (
686+ uid ,
677687 {
678- id : 1 ,
679- selected : true ,
688+ bio : "test bio 2" ,
689+ socialProfiles : {
690+ github : "test github" ,
691+ website : "test website" ,
692+ } ,
680693 } ,
681- ] ,
682- } ) ;
694+ {
695+ badges : [
696+ {
697+ id : 1 ,
698+ } ,
699+ ] ,
700+ }
701+ ) ;
683702
684- await UserDAL . updateProfile (
685- uid ,
686- {
703+ const updatedUser2 = await UserDAL . getUser (
704+ uid ,
705+ "test add result filters"
706+ ) ;
707+ expect ( updatedUser2 . profileDetails ) . toStrictEqual ( {
687708 bio : "test bio 2" ,
709+ keyboard : "test keyboard" ,
688710 socialProfiles : {
711+ twitter : "test twitter" ,
689712 github : "test github" ,
690713 website : "test website" ,
691714 } ,
692- } ,
693- {
715+ } ) ;
716+ expect ( updatedUser2 . inventory ) . toStrictEqual ( {
694717 badges : [
695718 {
696719 id : 1 ,
697720 } ,
698721 ] ,
699- }
700- ) ;
701-
702- const updatedUser2 = await UserDAL . getUser ( uid , "test add result filters" ) ;
703- expect ( updatedUser2 . profileDetails ) . toStrictEqual ( {
704- bio : "test bio 2" ,
705- keyboard : "test keyboard" ,
706- socialProfiles : {
707- twitter : "test twitter" ,
708- github : "test github" ,
709- website : "test website" ,
710- } ,
722+ } ) ;
711723 } ) ;
712- expect ( updatedUser2 . inventory ) . toStrictEqual ( {
713- badges : [
714- {
715- id : 1 ,
724+ it ( "should omit undefined or empty object values" , async ( ) => {
725+ //GIVEN
726+ const givenUser = await UserTestData . createUser ( {
727+ profileDetails : {
728+ bio : "test bio" ,
729+ keyboard : "test keyboard" ,
730+ socialProfiles : {
731+ twitter : "test twitter" ,
732+ github : "test github" ,
733+ } ,
716734 } ,
717- ] ,
735+ } ) ;
736+
737+ //WHEN
738+ await UserDAL . updateProfile ( givenUser . uid , {
739+ bio : undefined , //ignored
740+ keyboard : "updates" ,
741+ socialProfiles : { } , //ignored
742+ } ) ;
743+
744+ //THEN
745+ const read = await UserDAL . getUser ( givenUser . uid , "read" ) ;
746+ expect ( read . profileDetails ) . toStrictEqual ( {
747+ ...givenUser . profileDetails ,
748+ keyboard : "updates" ,
749+ } ) ;
718750 } ) ;
719751 } ) ;
720752
0 commit comments