@@ -228,4 +228,42 @@ describe('Event API service - post', () => {
228228
229229 expect ( res . body . errors [ 0 ] ) . toStrictEqual ( [ 'Props must be an array' ] )
230230 } )
231+
232+ it ( 'should add valid meta props to the player\'s props' , async ( ) => {
233+ apiKey . scopes = [ APIKeyScope . WRITE_EVENTS ]
234+ await ( < EntityManager > app . context . em ) . flush ( )
235+ token = await createToken ( apiKey )
236+
237+ await request ( app . callback ( ) )
238+ . post ( `${ baseUrl } ` )
239+ . send ( {
240+ events : [
241+ { name : 'Equip bow' , aliasId : validPlayer . aliases [ 0 ] . id , timestamp : Date . now ( ) , props : [ { key : 'META_OS' , value : 'macOS' } ] }
242+ ]
243+ } )
244+ . auth ( token , { type : 'bearer' } )
245+ . expect ( 200 )
246+
247+ const player = await ( < EntityManager > app . context . em ) . getRepository ( Player ) . findOne ( validPlayer . id , { refresh : true } )
248+ expect ( player . props ) . toContainEqual ( { key : 'META_OS' , value : 'macOS' } )
249+ } )
250+
251+ it ( 'should strip out event props that start with META_ but aren\'t in the meta props list' , async ( ) => {
252+ apiKey . scopes = [ APIKeyScope . WRITE_EVENTS ]
253+ await ( < EntityManager > app . context . em ) . flush ( )
254+ token = await createToken ( apiKey )
255+
256+ const res = await request ( app . callback ( ) )
257+ . post ( `${ baseUrl } ` )
258+ . send ( {
259+ events : [
260+ { name : 'Equip bow' , aliasId : validPlayer . aliases [ 0 ] . id , timestamp : Date . now ( ) , props : [ { key : 'META_NO_WAY' , value : 'true' } , { key : 'META_OS' , value : 'macOS' } ] }
261+ ]
262+ } )
263+ . auth ( token , { type : 'bearer' } )
264+ . expect ( 200 )
265+
266+ expect ( res . body . events [ 0 ] . props ) . toContainEqual ( { key : 'META_OS' , value : 'macOS' } )
267+ expect ( res . body . events [ 0 ] . props ) . not . toContainEqual ( { key : 'META_NO_WAY' , value : 'true' } )
268+ } )
231269} )
0 commit comments