@@ -866,19 +866,13 @@ mod tests {
866866 let pool = create_test_pool ( ) . await ;
867867 let repo = SqliteOrganizationRepo :: new ( pool) ;
868868
869- // Create 3 orgs
870- let org1 = repo
871- . create ( create_org_input ( "cursor-test-1" , "Org 1" ) )
872- . await
873- . expect ( "Failed to create org 1" ) ;
874- let org2 = repo
875- . create ( create_org_input ( "cursor-test-2" , "Org 2" ) )
876- . await
877- . expect ( "Failed to create org 2" ) ;
878- let _org3 = repo
879- . create ( create_org_input ( "cursor-test-3" , "Org 3" ) )
880- . await
881- . expect ( "Failed to create org 3" ) ;
869+ // Create 3 orgs (all may share the same millisecond timestamp,
870+ // so sort order is by created_at DESC, id DESC — not creation order)
871+ for i in 1 ..=3 {
872+ repo. create ( create_org_input ( & format ! ( "cursor-test-{i}" ) , & format ! ( "Org {i}" ) ) )
873+ . await
874+ . unwrap_or_else ( |_| panic ! ( "Failed to create org {i}" ) ) ;
875+ }
882876
883877 // Get first page with limit 2
884878 let page1 = repo
@@ -889,10 +883,13 @@ mod tests {
889883 . await
890884 . expect ( "Failed to list" ) ;
891885
892- // Most recent orgs should be first (descending order)
893- // The next cursor should point to the last item in the result (org2)
886+ assert_eq ! ( page1. items. len( ) , 2 ) ;
887+
888+ // Next cursor should point to the last item on this page
894889 let next_cursor = page1. cursors . next . expect ( "Should have next cursor" ) ;
895- assert_eq ! ( next_cursor. id, org2. id) ;
890+ assert_eq ! ( next_cursor. id, page1. items[ 1 ] . id) ;
891+ // First page has no prev cursor
892+ assert ! ( page1. cursors. prev. is_none( ) ) ;
896893
897894 // Navigate to next page using cursor
898895 let page2 = repo
@@ -905,13 +902,16 @@ mod tests {
905902 . await
906903 . expect ( "Failed to list page 2" ) ;
907904
908- // Should get org1 ( the oldest)
905+ // Should get the remaining org
909906 assert_eq ! ( page2. items. len( ) , 1 ) ;
910- assert_eq ! ( page2. items[ 0 ] . id, org1. id) ;
907+ // It should be the one not on page1
908+ assert ! ( page1. items. iter( ) . all( |o| o. id != page2. items[ 0 ] . id) ) ;
911909
912- // Prev cursor should point to first item of page2 (org1)
910+ // Prev cursor should point to first item of page2
913911 let prev_cursor = page2. cursors . prev . expect ( "Should have prev cursor" ) ;
914- assert_eq ! ( prev_cursor. id, org1. id) ;
912+ assert_eq ! ( prev_cursor. id, page2. items[ 0 ] . id) ;
913+ // Last page has no next cursor
914+ assert ! ( page2. cursors. next. is_none( ) ) ;
915915 }
916916
917917 #[ tokio:: test]
0 commit comments