From 9876817e6f870215067602d806fca08c21e934f5 Mon Sep 17 00:00:00 2001 From: Varsha Menon Date: Thu, 5 Dec 2024 15:35:32 -0500 Subject: [PATCH] feat: modify segment event to remove message content --- src/data/thunks.js | 1 - src/data/thunks.test.js | 44 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/data/thunks.js b/src/data/thunks.js index fb84955c..2bf2528a 100644 --- a/src/data/thunks.js +++ b/src/data/thunks.js @@ -46,7 +46,6 @@ export function addChatMessage(role, content, courseId, promptExperimentVariatio user_id: userId, timestamp: message.timestamp, role: message.role, - content: message.content, ...(promptExperimentVariationKey ? { experiment_name: OPTIMIZELY_PROMPT_EXPERIMENT_KEY, variation_key: promptExperimentVariationKey, diff --git a/src/data/thunks.test.js b/src/data/thunks.test.js index 439b9e49..a59c9b14 100644 --- a/src/data/thunks.test.js +++ b/src/data/thunks.test.js @@ -1,14 +1,56 @@ +import { sendTrackEvent } from '@edx/frontend-platform/analytics'; + import { fetchLearningAssistantChatSummary } from './api'; -import { getLearningAssistantChatSummary } from './thunks'; +import { addChatMessage, getLearningAssistantChatSummary } from './thunks'; jest.mock('./api'); +jest.mock('@edx/frontend-platform/analytics', () => ({ + sendTrackEvent: jest.fn(), +})); +const userId = 5; +jest.mock('@edx/frontend-platform/auth', () => ({ + getAuthenticatedUser: jest.fn().mockReturnValue({ userId }), +})); + +const mockState = { + learningAssistant: { messageList: [] }, +}; describe('Thunks unit tests', () => { const dispatch = jest.fn(); + const getState = jest.fn().mockReturnValue(mockState); afterEach(() => jest.resetAllMocks()); + describe('addChatMessage()', () => { + const mockDate = new Date(2024, 1, 1); + beforeAll(() => { + jest.useFakeTimers('modern'); + jest.setSystemTime(mockDate); + }); + + it('sends track event correctly, without content', async () => { + const courseId = 'course-v1:edx+test+23'; + const role = 'user'; + const content = 'hello!'; + await addChatMessage(role, content, courseId)(dispatch, getState); + + const eventName = 'edx.ui.lms.learning_assistant.message'; + const properties = { + course_id: courseId, + id: undefined, + role, + timestamp: mockDate.toString(), + user_id: userId, + }; + expect(sendTrackEvent).toHaveBeenCalledWith( + eventName, + properties, + ); + }); + }); + describe('getLearningAssistantChatSummary()', () => { const courseId = 'course-v1:edx+test+23';