Skip to content

Commit

Permalink
Add priority tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cy-moi committed Aug 28, 2024
1 parent 9534087 commit 945ea4c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
31 changes: 30 additions & 1 deletion packages/rum-core/src/domain/assembly.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,35 @@ describe('rum assembly', () => {
})
})

describe('priority of rum context', () => {
it('should prioritize view customer context over global context', () => {
const { lifeCycle } = setupBuilder.build()
commonContext.context = { foo: 'bar' }
notifyRawRumEvent(lifeCycle, {
customerContext: { foo: 'baz' },
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
})

expect(serverRumEvents[0].context!.foo).toBe('baz')
})

it('should prioritize child customer context over inherited view context', () => {
const { lifeCycle } = setupBuilder.build()
findView = () => ({
id: '7890',
name: 'view name',
startClocks: {} as ClocksState,
customerContext: { foo: 'bar' },
})
notifyRawRumEvent(lifeCycle, {
customerContext: { foo: 'baz' },
rawRumEvent: createRawRumEvent(RumEventType.ACTION),
})

expect(serverRumEvents[0].context!.foo).toBe('baz')
})
})

describe('rum global context', () => {
it('should be merged with event attributes', () => {
const { lifeCycle } = setupBuilder.build()
Expand Down Expand Up @@ -595,7 +624,7 @@ describe('rum assembly', () => {
)
})

it('should have view custom context', () => {
it('child event should have view customer context', () => {
const { lifeCycle } = setupBuilder.build()
findView = () => ({
id: '7890',
Expand Down
1 change: 1 addition & 0 deletions packages/rum-core/src/domain/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export function startRumAssembly(
}

const serverRumEvent = combine(rumContext as RumContext & Context, rawRumEvent) as RumEvent & Context
console.log(viewContext.customerContext, customerContext)
serverRumEvent.context = combine(commonContext.context, viewContext.customerContext, customerContext)

if (!('has_replay' in serverRumEvent.session)) {
Expand Down

0 comments on commit 945ea4c

Please sign in to comment.