@@ -737,6 +737,68 @@ public async Task RevokeRootAsync_RevokesRootAndItsChains()
737737 ( await store . GetChainAsync ( secondChain . ChainId ) ) ! . IsRevoked . Should ( ) . BeTrue ( ) ;
738738 }
739739
740+ [ Fact ]
741+ public async Task GetUserChainsAsync_ReturnsTotalSessionCountPerChain ( )
742+ {
743+ var ( sut , store ) = CreateSut ( ) ;
744+ var user = UserKey . New ( ) ;
745+ var root = await CreateRootAsync ( store , user ) ;
746+
747+ var firstChain = CreateChain ( root , Now . AddMinutes ( - 30 ) ) ;
748+ var secondChain = CreateChain ( root , Now . AddMinutes ( - 20 ) ) ;
749+
750+ await store . CreateChainAsync ( firstChain ) ;
751+ await store . CreateChainAsync ( secondChain ) ;
752+
753+ var firstSession = CreateSession (
754+ user , firstChain . ChainId , Now . AddMinutes ( - 25 ) , "first-1" ) ;
755+
756+ var rotatedSession = CreateSession (
757+ user , firstChain . ChainId , Now . AddMinutes ( - 15 ) , "first-2" ) ;
758+
759+ var secondSession = CreateSession (
760+ user , secondChain . ChainId , Now . AddMinutes ( - 10 ) , "second-1" ) ;
761+
762+ await store . CreateSessionAsync ( firstSession ) ;
763+ await store . CreateSessionAsync ( rotatedSession ) ;
764+ await store . CreateSessionAsync ( secondSession ) ;
765+
766+ var result = await sut . GetUserChainsAsync (
767+ Context ( user ) ,
768+ user ,
769+ new PageRequest { PageNumber = 1 , PageSize = 10 } ) ;
770+
771+ result . Items . Single ( x => x . ChainId == firstChain . ChainId )
772+ . SessionCount . Should ( ) . Be ( 2 ) ;
773+
774+ result . Items . Single ( x => x . ChainId == secondChain . ChainId )
775+ . SessionCount . Should ( ) . Be ( 1 ) ;
776+ }
777+
778+ [ Fact ]
779+ public async Task GetUserChainsAsync_RevokedSessionsRemainCounted ( )
780+ {
781+ var ( sut , store ) = CreateSut ( ) ;
782+ var user = UserKey . New ( ) ;
783+ var root = await CreateRootAsync ( store , user ) ;
784+
785+ var chain = CreateChain ( root , Now . AddMinutes ( - 30 ) ) ;
786+ await store . CreateChainAsync ( chain ) ;
787+
788+ var first = CreateSession ( user , chain . ChainId , Now . AddMinutes ( - 20 ) , "revoked-1" ) ;
789+
790+ var second = CreateSession ( user , chain . ChainId , Now . AddMinutes ( - 10 ) , "revoked-2" ) ;
791+
792+ await store . CreateSessionAsync ( first ) ;
793+ await store . CreateSessionAsync ( second ) ;
794+
795+ await store . RevokeChainCascadeAsync ( chain . ChainId , Now ) ;
796+
797+ var result = await sut . GetUserChainsAsync ( Context ( user ) , user , new PageRequest { PageNumber = 1 , PageSize = 10 } ) ;
798+
799+ result . Items . Single ( x => x . ChainId == chain . ChainId ) . SessionCount . Should ( ) . Be ( 2 ) ;
800+ }
801+
740802 // ---------------------------------------------------------------------
741803 // Infrastructure / Helpers
742804 // ---------------------------------------------------------------------
0 commit comments