-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
50668f5
commit 6432c4a
Showing
6 changed files
with
81 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 41 additions & 25 deletions
66
packages/rum/src/domain/segmentCollection/buildReplayPayload.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,49 @@ | ||
import { toFormEntries } from './buildReplayPayload' | ||
import pako from 'pako' | ||
import type { BrowserSegment, BrowserSegmentMetadata } from '../../types' | ||
import { readReplayPayload } from '../../../test' | ||
import { buildReplayPayload } from './buildReplayPayload' | ||
|
||
describe('toFormEntries', () => { | ||
let callbackSpy: jasmine.Spy<(key: string, value: string) => void> | ||
describe('buildReplayPayload', () => { | ||
const SEGMENT = { foo: 'bar' } as unknown as BrowserSegment | ||
const SERIALIZED_SEGMENT = JSON.stringify(SEGMENT) | ||
const COMPRESSED_SEGMENT = pako.deflate(SERIALIZED_SEGMENT) | ||
const METADATA: BrowserSegmentMetadata = { | ||
application: { id: 'xxx' }, | ||
session: { id: 'xxx' }, | ||
view: { id: 'xxx' }, | ||
start: 1, | ||
end: 2, | ||
records_count: 10, | ||
source: 'browser', | ||
creation_reason: 'init', | ||
} | ||
const METADATA_AND_SEGMENT_SIZES = { | ||
...METADATA, | ||
raw_segment_size: SERIALIZED_SEGMENT.length, | ||
} | ||
|
||
beforeEach(() => { | ||
callbackSpy = jasmine.createSpy() | ||
it('adds the segment as a file', async () => { | ||
const payload = buildReplayPayload(COMPRESSED_SEGMENT, METADATA, SERIALIZED_SEGMENT.length) | ||
const segmentEntry = (payload.data as FormData).get('segment')! as File | ||
expect(segmentEntry.size).toBe(COMPRESSED_SEGMENT.byteLength) | ||
expect(segmentEntry.name).toBe('xxx-1') | ||
expect(segmentEntry.type).toBe('application/octet-stream') | ||
const { segment } = await readReplayPayload(payload) | ||
expect(segment).toEqual(SEGMENT) | ||
}) | ||
|
||
it('handles top level properties', () => { | ||
toFormEntries({ foo: 'bar', zig: 'zag' }, callbackSpy) | ||
expect(callbackSpy.calls.allArgs()).toEqual([ | ||
['foo', 'bar'], | ||
['zig', 'zag'], | ||
]) | ||
it('adds the metadata plus the segment sizes as the `event` entry', async () => { | ||
const payload = buildReplayPayload(COMPRESSED_SEGMENT, METADATA, SERIALIZED_SEGMENT.length) | ||
const eventEntry = (payload.data as FormData).get('event')! as File | ||
expect(eventEntry.size).toBe(JSON.stringify(METADATA_AND_SEGMENT_SIZES).length) | ||
expect(eventEntry.name).toBe('blob') | ||
expect(eventEntry.type).toBe('application/json') | ||
const { metadata } = await readReplayPayload(payload) | ||
expect(metadata).toEqual(METADATA_AND_SEGMENT_SIZES) | ||
}) | ||
|
||
it('handles nested properties', () => { | ||
toFormEntries({ foo: { bar: 'baz', zig: { zag: 'zug' } } }, callbackSpy) | ||
expect(callbackSpy.calls.allArgs()).toEqual([ | ||
['foo.bar', 'baz'], | ||
['foo.zig.zag', 'zug'], | ||
]) | ||
}) | ||
|
||
it('converts values to string', () => { | ||
toFormEntries({ foo: 42, bar: null }, callbackSpy) | ||
expect(callbackSpy.calls.allArgs()).toEqual([ | ||
['foo', '42'], | ||
['bar', 'null'], | ||
]) | ||
it('returns the approximative byte counts of the request', () => { | ||
const payload = buildReplayPayload(COMPRESSED_SEGMENT, METADATA, SERIALIZED_SEGMENT.length) | ||
expect(payload.bytesCount).toBe(COMPRESSED_SEGMENT.byteLength) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters