@@ -541,7 +541,8 @@ describe('authorizeByCart', function () {
541541 const fakeCart : Cart = {
542542 cart_id : 'cart-1' ,
543543 cart_status : CartStatus . ACTIVE ,
544- system_user_id : 1
544+ system_user_id : 1 ,
545+ record_end_date : null
545546 } ;
546547
547548 const systemUser : SystemUser = {
@@ -569,7 +570,8 @@ describe('authorizeByCart', function () {
569570 const fakeCart : Cart = {
570571 cart_id : 'cart-1' ,
571572 system_user_id : 1 ,
572- cart_status : CartStatus . ACTIVE
573+ cart_status : CartStatus . ACTIVE ,
574+ record_end_date : null
573575 } ;
574576
575577 sinon . stub ( CartService . prototype , 'findCartById' ) . resolves ( fakeCart ) ;
@@ -592,7 +594,8 @@ describe('authorizeByCart', function () {
592594 const fakeCartWithDifferentOwner : Cart = {
593595 cart_id : 'cart-1' ,
594596 cart_status : CartStatus . ACTIVE ,
595- system_user_id : 2
597+ system_user_id : 2 ,
598+ record_end_date : null
596599 } ;
597600 sinon . stub ( CartService . prototype , 'findCartById' ) . resolves ( fakeCartWithDifferentOwner ) ;
598601 sinon . stub ( AuthorizationService . prototype , 'getCachedSystemUser' ) . resolves ( systemUser ) ;
@@ -612,7 +615,8 @@ describe('authorizeByCart', function () {
612615 const fakeUnauthenticatedCart : Cart = {
613616 cart_id : 'cart-1' ,
614617 cart_status : CartStatus . ACTIVE ,
615- system_user_id : null // No system_user_id, indicating it's unauthenticated
618+ system_user_id : null , // No system_user_id, indicating it's unauthenticated
619+ record_end_date : null
616620 } ;
617621 sinon . stub ( CartService . prototype , 'findCartById' ) . resolves ( fakeUnauthenticatedCart ) ;
618622 sinon . stub ( AuthorizationService . prototype , 'getCachedSystemUser' ) . resolves ( systemUser ) ;
@@ -656,6 +660,108 @@ describe('authorizeByCart', function () {
656660
657661 expect ( result ) . to . be . false ;
658662 } ) ;
663+
664+ it ( 'returns false if cart is checked out' , async function ( ) {
665+ const mockDBConnection = getMockDBConnection ( ) ;
666+ sinon . stub ( CartService . prototype , 'findCartById' ) . resolves ( {
667+ cart_id : 'cart-1' ,
668+ cart_status : CartStatus . CHECKED_OUT ,
669+ system_user_id : 1 ,
670+ record_end_date : null
671+ } ) ;
672+ sinon . stub ( AuthorizationService . prototype , 'getCachedSystemUser' ) . resolves ( systemUser ) ;
673+
674+ const authorizationService = new AuthorizationService ( mockDBConnection ) ;
675+
676+ const result = await authorizationService . authorizeByCart ( {
677+ discriminator : 'Cart' ,
678+ cartId : 'cart-1'
679+ } ) ;
680+
681+ expect ( result ) . to . be . false ;
682+ } ) ;
683+
684+ it ( 'returns false if cart is expired' , async function ( ) {
685+ const mockDBConnection = getMockDBConnection ( ) ;
686+ sinon . stub ( CartService . prototype , 'findCartById' ) . resolves ( {
687+ cart_id : 'cart-1' ,
688+ cart_status : CartStatus . EXPIRED ,
689+ system_user_id : 1 ,
690+ record_end_date : null
691+ } ) ;
692+ sinon . stub ( AuthorizationService . prototype , 'getCachedSystemUser' ) . resolves ( systemUser ) ;
693+
694+ const authorizationService = new AuthorizationService ( mockDBConnection ) ;
695+
696+ const result = await authorizationService . authorizeByCart ( {
697+ discriminator : 'Cart' ,
698+ cartId : 'cart-1'
699+ } ) ;
700+
701+ expect ( result ) . to . be . false ;
702+ } ) ;
703+
704+ it ( 'returns false if cart is abandoned' , async function ( ) {
705+ const mockDBConnection = getMockDBConnection ( ) ;
706+ sinon . stub ( CartService . prototype , 'findCartById' ) . resolves ( {
707+ cart_id : 'cart-1' ,
708+ cart_status : CartStatus . ABANDONED ,
709+ system_user_id : 1 ,
710+ record_end_date : null
711+ } ) ;
712+ sinon . stub ( AuthorizationService . prototype , 'getCachedSystemUser' ) . resolves ( systemUser ) ;
713+
714+ const authorizationService = new AuthorizationService ( mockDBConnection ) ;
715+
716+ const result = await authorizationService . authorizeByCart ( {
717+ discriminator : 'Cart' ,
718+ cartId : 'cart-1'
719+ } ) ;
720+
721+ expect ( result ) . to . be . false ;
722+ } ) ;
723+
724+ it ( 'returns false if cart record_end_date is in the past' , async function ( ) {
725+ const mockDBConnection = getMockDBConnection ( ) ;
726+ sinon . stub ( CartService . prototype , 'findCartById' ) . resolves ( {
727+ cart_id : 'cart-1' ,
728+ cart_status : CartStatus . ACTIVE ,
729+ system_user_id : 1 ,
730+ record_end_date : '2000-01-01T00:00:00.000Z'
731+ } ) ;
732+ sinon . stub ( AuthorizationService . prototype , 'getCachedSystemUser' ) . resolves ( systemUser ) ;
733+
734+ const authorizationService = new AuthorizationService ( mockDBConnection ) ;
735+
736+ const result = await authorizationService . authorizeByCart ( {
737+ discriminator : 'Cart' ,
738+ cartId : 'cart-1'
739+ } ) ;
740+
741+ expect ( result ) . to . be . false ;
742+ } ) ;
743+
744+ it ( 'returns true if cart record_end_date is in the future and user owns the cart' , async function ( ) {
745+ const mockDBConnection = getMockDBConnection ( ) ;
746+ sinon . stub ( CartService . prototype , 'findCartById' ) . resolves ( {
747+ cart_id : 'cart-1' ,
748+ cart_status : CartStatus . ACTIVE ,
749+ system_user_id : 1 ,
750+ record_end_date : '2999-01-01T00:00:00.000Z'
751+ } ) ;
752+
753+ const systemUser = { system_user_id : 1 } as SystemUserExtended ;
754+ sinon . stub ( AuthorizationService . prototype , 'getCachedSystemUser' ) . resolves ( systemUser ) ;
755+
756+ const authorizationService = new AuthorizationService ( mockDBConnection ) ;
757+
758+ const result = await authorizationService . authorizeByCart ( {
759+ discriminator : 'Cart' ,
760+ cartId : 'cart-1'
761+ } ) ;
762+
763+ expect ( result ) . to . be . true ;
764+ } ) ;
659765} ) ;
660766
661767describe ( 'hasAtLeastOneValidValue' , ( ) => {
0 commit comments