Skip to content

Commit

Permalink
test: mock date
Browse files Browse the repository at this point in the history
  • Loading branch information
varshamenon4 committed Dec 13, 2024
1 parent dcc8a8f commit 15e4565
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/data/thunks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ 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: 5 }),
getAuthenticatedUser: jest.fn().mockReturnValue({ userId }),
}));

const mockState = {
Expand All @@ -23,17 +24,31 @@ describe('Thunks unit tests', () => {
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);

// "edx.ui.lms.learning_assistant.message",
// {"course_id": "course-v1:edx+test+23", "id": undefined, "role": "user", "timestamp": "Wed Dec 11 2024 14:42:37 GMT-0500 (Eastern Standard Time)", "user_id": 5});
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()', () => {
Expand Down

0 comments on commit 15e4565

Please sign in to comment.