@@ -746,4 +746,109 @@ describe('[INTEGRATION] Stream client (Node)', function () {
746746 expect ( resp . export . activity_ids ) . to . eql ( [ activityRes . id ] ) ;
747747 expect ( resp . export . reaction_ids ) . to . eql ( [ reaction1 . id , reaction3 . id ] ) ;
748748 } ) ;
749+
750+ describe ( 'Audit Logs' , function ( ) {
751+ it ( 'filter audit logs by entity type and ID' , async function ( ) {
752+ // First create an activity to generate an audit log
753+ const activity = {
754+ actor : 'user:1' ,
755+ verb : 'tweet' ,
756+ object : '1' ,
757+ foreign_id : `audit-test-${ Date . now ( ) } ` ,
758+ } ;
759+
760+ const activityRes = await this . user1 . addActivity ( activity ) ;
761+
762+ // Filter audit logs for this activity
763+ const response = await this . client . auditLogs . filter ( {
764+ entity_type : 'activity' ,
765+ entity_id : activityRes . id ,
766+ limit : 5 ,
767+ } ) ;
768+
769+ // Verify response structure
770+ expect ( response ) . to . have . property ( 'duration' ) ;
771+ expect ( response ) . to . have . property ( 'audit_logs' ) ;
772+ expect ( Array . isArray ( response . audit_logs ) ) . to . be ( true ) ;
773+
774+ // There should be at least one audit log for this activity
775+ expect ( response . audit_logs . length ) . to . be . greaterThan ( 0 ) ;
776+
777+ // Check log structure
778+ const log = response . audit_logs [ 0 ] ;
779+ expect ( log ) . to . have . property ( 'entity_type' ) ;
780+ expect ( log ) . to . have . property ( 'entity_id' ) ;
781+ expect ( log ) . to . have . property ( 'action' ) ;
782+ expect ( log ) . to . have . property ( 'user_id' ) ;
783+ expect ( log ) . to . have . property ( 'created_at' ) ;
784+ } ) ;
785+
786+ it ( 'filter audit logs with pagination' , async function ( ) {
787+ // First create an activity to generate an audit log
788+ const activity = {
789+ actor : 'user:1' ,
790+ verb : 'tweet' ,
791+ object : '1' ,
792+ foreign_id : `audit-pagination-test-${ Date . now ( ) } ` ,
793+ } ;
794+
795+ const activityRes = await this . user1 . addActivity ( activity ) ;
796+
797+ // Filter with a small limit to ensure pagination
798+ const response = await this . client . auditLogs . filter ( {
799+ entity_type : 'activity' ,
800+ entity_id : activityRes . id ,
801+ limit : 1 ,
802+ } ) ;
803+
804+ // Verify response structure includes pagination
805+ expect ( response ) . to . have . property ( 'next' ) ;
806+
807+ // If there's more than one result, test pagination
808+ if ( response . next ) {
809+ const nextPage = await this . client . auditLogs . filter ( {
810+ entity_type : 'activity' ,
811+ entity_id : activityRes . id ,
812+ limit : 1 ,
813+ next : response . next ,
814+ } ) ;
815+
816+ expect ( nextPage ) . to . have . property ( 'audit_logs' ) ;
817+ expect ( Array . isArray ( nextPage . audit_logs ) ) . to . be ( true ) ;
818+
819+ // Next page should have results
820+ expect ( nextPage . audit_logs . length ) . to . be ( 1 ) ;
821+
822+ // Next page should have different results
823+ if ( response . audit_logs . length > 0 && nextPage . audit_logs . length > 0 ) {
824+ expect ( response . audit_logs [ 0 ] . id ) . to . not . eql ( nextPage . audit_logs [ 0 ] . id ) ;
825+ }
826+ }
827+ } ) ;
828+
829+ it ( 'filter audit logs by user ID' , async function ( ) {
830+ // Create an activity with a specific user ID
831+ const userId = randUserId ( 'audit' ) ;
832+ const activity = {
833+ actor : userId ,
834+ verb : 'tweet' ,
835+ object : '1' ,
836+ foreign_id : `audit-user-test-${ Date . now ( ) } ` ,
837+ } ;
838+
839+ await this . user1 . addActivity ( activity ) ;
840+
841+ // Filter audit logs for this user
842+ const response = await this . client . auditLogs . filter ( {
843+ user_id : userId ,
844+ limit : 5 ,
845+ } ) ;
846+
847+ // Check that we get logs for this user
848+ if ( response . audit_logs . length > 0 ) {
849+ const log = response . audit_logs [ 0 ] ;
850+ expect ( log . user_id ) . to . be ( userId ) ;
851+ }
852+ } ) ;
853+ } ) ;
749854} ) ;
0 commit comments