Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(plugins): add test for sending events that are not current sessions current sequence #521

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export interface SessionReplayContext {

export enum RecordingStatus {
RECORDING = 'recording',
SENDING = 'sending',
SENT = 'sent',
}

Expand Down Expand Up @@ -49,6 +48,7 @@ export interface SessionReplayEnrichmentPlugin extends EnrichmentPlugin {
stopRecordingEvents: ReturnType<typeof record> | null;
maxPersistedEventsSize: number;
initialize: (shouldSendStoredEvents?: boolean) => Promise<void>;
sendStoredEvents: (storedReplaySessions: IDBStore) => void;
getShouldRecord: () => boolean;
recordEvents: () => void;
shouldSplitEventsList: (nextEventString: string) => boolean;
Expand Down
71 changes: 68 additions & 3 deletions packages/plugin-session-replay-browser/test/session-replay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ describe('SessionReplayPlugin', () => {
expect(getAllSessionEventsFromStore).toHaveBeenCalled();
expect(sessionReplay.events).toEqual([]); // events should not be updated to match what is in the store
});
test('should configure current sequence id and events correctly if last sequence was sending', async () => {
test('should configure current sequence id and events correctly if last sequence was sent', async () => {
const sessionReplay = sessionReplayPlugin();
sessionReplay.config = mockConfig;
const mockGetResolution: Promise<IDBStore> = Promise.resolve({
Expand All @@ -282,7 +282,7 @@ describe('SessionReplayPlugin', () => {
sessionSequences: {
3: {
events: [mockEventString],
status: RecordingStatus.SENDING,
status: RecordingStatus.SENT,
},
},
},
Expand Down Expand Up @@ -342,6 +342,71 @@ describe('SessionReplayPlugin', () => {
await sessionReplay.initialize();
expect(record).toHaveBeenCalledTimes(1);
});
describe('sendStoredEvents', () => {
test('should send all recording sequences except the current sequence for the current session', () => {
const sessionReplay = sessionReplayPlugin();
const config = {
...mockConfig,
sessionId: 456,
};
sessionReplay.config = config;
sessionReplay.currentSequenceId = 3;
const store: IDBStore = {
123: {
currentSequenceId: 5,
sessionSequences: {
3: {
events: [mockEventString],
status: RecordingStatus.RECORDING,
},
4: {
events: [],
status: RecordingStatus.SENT,
},
5: {
events: [mockEventString, mockEventString],
status: RecordingStatus.RECORDING,
},
},
},
456: {
currentSequenceId: 3,
sessionSequences: {
1: {
events: [mockEventString],
status: RecordingStatus.RECORDING,
},
2: {
events: [],
status: RecordingStatus.SENT,
},
3: {
events: [mockEventString],
status: RecordingStatus.RECORDING,
},
},
},
};
const sendEventsList = jest.spyOn(sessionReplay, 'sendEventsList');
sessionReplay.sendStoredEvents(store);
expect(sendEventsList).toHaveBeenCalledTimes(3);
expect(sendEventsList.mock.calls[0][0]).toEqual({
events: [mockEventString],
sequenceId: 3,
sessionId: 123,
});
expect(sendEventsList.mock.calls[1][0]).toEqual({
events: [mockEventString, mockEventString],
sequenceId: 5,
sessionId: 123,
});
expect(sendEventsList.mock.calls[2][0]).toEqual({
events: [mockEventString],
sequenceId: 1,
sessionId: 456,
});
});
});
describe('defaultTracking', () => {
test('should not change defaultTracking if its set to true', async () => {
const sessionReplay = sessionReplayPlugin();
Expand Down Expand Up @@ -1271,7 +1336,7 @@ describe('SessionReplayPlugin', () => {
sessionSequences: {
3: {
events: [mockEventString],
status: RecordingStatus.SENDING,
status: RecordingStatus.RECORDING,
},
},
},
Expand Down