@@ -14,12 +14,14 @@ const getSession = jest.fn(() => ({
1414const getUserId = jest . fn ( ( ) => 'b' ) ;
1515const getAttributes = jest . fn ( ) ;
1616const incrementSessionEventCount = jest . fn ( ) ;
17+ const addSessionAttributes = jest . fn ( ) ;
1718jest . mock ( '../../sessions/SessionManager' , ( ) => ( {
1819 SessionManager : jest . fn ( ) . mockImplementation ( ( ) => ( {
1920 getSession,
2021 getUserId,
2122 getAttributes,
22- incrementSessionEventCount
23+ incrementSessionEventCount,
24+ addSessionAttributes
2325 } ) )
2426} ) ) ;
2527
@@ -236,7 +238,7 @@ describe('EventCache tests', () => {
236238 timestamp : new Date ( ) ,
237239 type : EVENT1_SCHEMA ,
238240 metadata :
239- '{"version":"1.0.0"," title":"","pageId":"/rum/home","pageTags":["pageGroup1"]}' ,
241+ '{"title":"","pageId":"/rum/home","pageTags":["pageGroup1"],"version":"1.0.0" }' ,
240242 details : '{"version":"1.0.0","pageId":"/rum/home"}'
241243 }
242244 ] ;
@@ -253,6 +255,66 @@ describe('EventCache tests', () => {
253255 ) ;
254256 } ) ;
255257
258+ test ( 'when page is recorded with custom page attributes, metadata records the custom page attributes' , async ( ) => {
259+ // Init
260+ const EVENT1_SCHEMA = 'com.amazon.rum.page_view_event' ;
261+ const eventCache : EventCache = Utils . createEventCache ( {
262+ ...DEFAULT_CONFIG
263+ } ) ;
264+ const expectedEvents : RumEvent [ ] = [
265+ {
266+ id : expect . stringMatching ( / [ 0 - 9 a - f \- ] + / ) ,
267+ timestamp : new Date ( ) ,
268+ type : EVENT1_SCHEMA ,
269+ metadata :
270+ '{"customPageAttributeString":"customPageAttributeValue","customPageAttributeNumber":1,"customPageAttributeBoolean":true,"title":"","pageId":"/rum/home","pageTags":["pageGroup1"],"version":"1.0.0"}' ,
271+ details : '{"version":"1.0.0","pageId":"/rum/home"}'
272+ }
273+ ] ;
274+
275+ // Run
276+ eventCache . recordPageView ( {
277+ pageId : '/rum/home' ,
278+ pageTags : [ 'pageGroup1' ] ,
279+ pageAttributes : {
280+ customPageAttributeString : 'customPageAttributeValue' ,
281+ customPageAttributeNumber : 1 ,
282+ customPageAttributeBoolean : true
283+ }
284+ } ) ;
285+
286+ // Assert
287+ expect ( eventCache . getEventBatch ( ) ) . toEqual (
288+ expect . arrayContaining ( expectedEvents )
289+ ) ;
290+ } ) ;
291+
292+ /**
293+ * Test title truncated to meet lint requirements
294+ * Full title: when EventCache.addSessionAttributes() is called then SessionManager.addSessionAttributes() is called
295+ */
296+ test ( 'EventCache.addSessionAttributes() calls SessionManager.addSessionAttributes()' , async ( ) => {
297+ // Init
298+ const eventCache : EventCache = Utils . createEventCache ( {
299+ ...DEFAULT_CONFIG
300+ } ) ;
301+
302+ const expected = {
303+ customAttributeString : 'customAttributeValue' ,
304+ customAttributeNumber : 1 ,
305+ customAttributeBoolean : true
306+ } ;
307+
308+ // Run
309+ eventCache . addSessionAttributes ( expected ) ;
310+
311+ // Assert
312+ expect ( addSessionAttributes ) . toHaveBeenCalledTimes ( 1 ) ;
313+ const actual = addSessionAttributes . mock . calls [ 0 ] [ 0 ] ;
314+
315+ expect ( actual ) . toEqual ( expected ) ;
316+ } ) ;
317+
256318 test ( 'when page matches both allowed and denied, recordEvent does not record the event' , async ( ) => {
257319 // Init
258320 const EVENT1_SCHEMA = 'com.amazon.rum.event1' ;
0 commit comments