@@ -80,6 +80,68 @@ describe('api: /projects/:id/app-users', () => {
8080 body . properties . should . eql ( { region : 'north' } ) ;
8181 } ) ;
8282 } ) ) ;
83+
84+ it ( 'should log the property set in the audit log' , testService ( async ( service , container ) => {
85+ const asAlice = await service . login ( 'alice' ) ;
86+ await asAlice . post ( '/v1/projects/1/actor-properties' ) . send ( { name : 'region' } ) . expect ( 200 ) ;
87+
88+ const { body : appUser } = await asAlice . post ( '/v1/projects/1/app-users' )
89+ . send ( {
90+ displayName : 'test user' ,
91+ properties : { region : 'north' }
92+ } )
93+ . expect ( 200 ) ;
94+
95+ const actor = await container . Actors . getById ( appUser . id ) . then ( ( o ) => o . get ( ) ) ;
96+
97+ const { body : audits } = await asAlice . get ( '/v1/audits?action=field_key.property.set' ) . expect ( 200 ) ;
98+ audits . length . should . equal ( 1 ) ;
99+ audits [ 0 ] . actorId . should . equal ( 5 ) ; // alice
100+ audits [ 0 ] . acteeId . should . equal ( actor . acteeId ) ;
101+ audits [ 0 ] . details . properties . should . eql ( { region : 'north' } ) ;
102+ } ) ) ;
103+
104+ it ( 'should not log add audit log event if property set is empty' , testService ( async ( service ) => {
105+ const asAlice = await service . login ( 'alice' ) ;
106+ await asAlice . post ( '/v1/projects/1/actor-properties' ) . send ( { name : 'region' } ) . expect ( 200 ) ;
107+
108+ await asAlice . post ( '/v1/projects/1/app-users' )
109+ . send ( {
110+ displayName : 'test user' ,
111+ properties : { }
112+ } )
113+ . expect ( 200 ) ;
114+
115+ const { body : audits } = await asAlice . get ( '/v1/audits?action=field_key.property.set' ) . expect ( 200 ) ;
116+ audits . length . should . equal ( 0 ) ;
117+ } ) ) ;
118+
119+ it ( 'should log when a property is unset in the audit log' , testService ( async ( service , container ) => {
120+ const asAlice = await service . login ( 'alice' ) ;
121+ await asAlice . post ( '/v1/projects/1/actor-properties' ) . send ( { name : 'region' } ) . expect ( 200 ) ;
122+ await asAlice . post ( '/v1/projects/1/actor-properties' ) . send ( { name : 'team' } ) . expect ( 200 ) ;
123+
124+ const { body : appUser } = await asAlice . post ( '/v1/projects/1/app-users' )
125+ . send ( {
126+ displayName : 'test user' ,
127+ properties : { team : 'abc' , region : 'north' }
128+ } )
129+ . expect ( 200 ) ;
130+
131+ // unset a property
132+ await asAlice . patch ( `/v1/projects/1/app-users/${ appUser . id } ` )
133+ . send ( { properties : { region : '' } } )
134+ . expect ( 200 ) ;
135+
136+ const actor = await container . Actors . getById ( appUser . id ) . then ( ( o ) => o . get ( ) ) ;
137+
138+ const { body : audits } = await asAlice . get ( '/v1/audits?action=field_key.property.set' ) . expect ( 200 ) ;
139+ audits . length . should . equal ( 2 ) ;
140+ audits [ 0 ] . actorId . should . equal ( 5 ) ; // alice
141+ audits [ 0 ] . acteeId . should . equal ( actor . acteeId ) ;
142+
143+ audits [ 0 ] . details . properties . should . eql ( { region : null } ) ;
144+ } ) ) ;
83145 } ) ;
84146
85147 describe ( 'GET' , ( ) => {
@@ -432,6 +494,27 @@ describe('api: /projects/:id/app-users', () => {
432494 // The property-setting logic (validation, coercion, bulk upsert/delete) is shared
433495 // under the hood with public links. The tests above cover it fully; public-links
434496 // tests only verify the happy-path integration without re-testing every edge case.
497+
498+ it ( 'should log the property set in the audit log' , testService ( async ( service , container ) => {
499+ const asAlice = await service . login ( 'alice' ) ;
500+ await asAlice . post ( '/v1/projects/1/actor-properties' ) . send ( { name : 'region' } ) . expect ( 200 ) ;
501+
502+ const { body : appUser } = await asAlice . post ( '/v1/projects/1/app-users' )
503+ . send ( { displayName : 'test user' } )
504+ . expect ( 200 ) ;
505+
506+ await asAlice . patch ( `/v1/projects/1/app-users/${ appUser . id } ` )
507+ . send ( { properties : { region : 'north' } } )
508+ . expect ( 200 ) ;
509+
510+ const actor = await container . Actors . getById ( appUser . id ) . then ( ( o ) => o . get ( ) ) ;
511+
512+ const { body : audits } = await asAlice . get ( '/v1/audits?action=field_key.property.set' ) . expect ( 200 ) ;
513+ audits . length . should . equal ( 1 ) ;
514+ audits [ 0 ] . actorId . should . equal ( 5 ) ; // alice
515+ audits [ 0 ] . acteeId . should . equal ( actor . acteeId ) ;
516+ audits [ 0 ] . details . properties . should . eql ( { region : 'north' } ) ;
517+ } ) ) ;
435518 } ) ;
436519
437520 describe ( '/:id DELETE' , ( ) => {
0 commit comments