Skip to content

Commit

Permalink
feat: modify segment event to remove message content
Browse files Browse the repository at this point in the history
  • Loading branch information
varshamenon4 committed Dec 13, 2024
1 parent c40ee8d commit 9876817
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
44 changes: 43 additions & 1 deletion src/data/thunks.test.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down

0 comments on commit 9876817

Please sign in to comment.