AA-492: Add event data for consumption in the backend (#355)

This commit is contained in:
Dillon Dumesnil
2021-02-01 09:46:21 -08:00
committed by GitHub
parent 8835a9cd6a
commit 629382f719
5 changed files with 22 additions and 11 deletions

View File

@@ -194,9 +194,12 @@ export async function getOutlineTabData(courseId) {
};
}
export async function postCourseDeadlines(courseId) {
export async function postCourseDeadlines(courseId, model) {
const url = new URL(`${getConfig().LMS_BASE_URL}/api/course_experience/v1/reset_course_deadlines`);
return getAuthenticatedHttpClient().post(url.href, { course_key: courseId });
return getAuthenticatedHttpClient().post(url.href, {
course_key: courseId,
research_event_data: { location: `${model}-tab` },
});
}
export async function postCourseGoals(courseId, goalKey) {
@@ -214,7 +217,10 @@ export async function postRequestCert(courseId) {
await getAuthenticatedHttpClient().post(url.href);
}
export async function executePostFromPostEvent(postData) {
export async function executePostFromPostEvent(postData, researchEventData) {
const url = new URL(postData.url);
return getAuthenticatedHttpClient().post(url.href, { course_key: postData.bodyParams.courseId });
return getAuthenticatedHttpClient().post(url.href, {
course_key: postData.bodyParams.courseId,
research_event_data: researchEventData,
});
}

View File

@@ -102,16 +102,17 @@ describe('Data layer integration tests', () => {
describe('Test resetDeadlines', () => {
it('Should reset course deadlines', async () => {
const resetUrl = `${getConfig().LMS_BASE_URL}/api/course_experience/v1/reset_course_deadlines`;
const model = 'dates';
axiosMock.onPost(resetUrl).reply(201, {});
const getTabDataMock = jest.fn(() => ({
type: 'MOCK_ACTION',
}));
await executeThunk(thunks.resetDeadlines(courseId, getTabDataMock), store.dispatch);
await executeThunk(thunks.resetDeadlines(courseId, model, getTabDataMock), store.dispatch);
expect(axiosMock.history.post[0].url).toEqual(resetUrl);
expect(axiosMock.history.post[0].data).toEqual(`{"course_key":"${courseId}"}`);
expect(axiosMock.history.post[0].data).toEqual(`{"course_key":"${courseId}","research_event_data":{"location":"dates-tab"}}`);
expect(getTabDataMock).toHaveBeenCalledWith(courseId);
});

View File

@@ -90,9 +90,9 @@ export function requestCert(courseId) {
return async () => postRequestCert(courseId);
}
export function resetDeadlines(courseId, getTabData) {
export function resetDeadlines(courseId, model, getTabData) {
return async (dispatch) => {
postCourseDeadlines(courseId).then(response => {
postCourseDeadlines(courseId, model).then(response => {
const { data } = response;
const {
header,
@@ -111,9 +111,12 @@ export async function saveCourseGoal(courseId, goalKey) {
export function processEvent(eventData, getTabData) {
return async (dispatch) => {
// Pulling this out early so the data doesn't get camelCased and is easier
// to use when it's passed to the backend
const { research_event_data: researchEventData } = eventData;
const event = camelCaseObject(eventData);
if (event.eventName === eventTypes.POST_EVENT) {
executePostFromPostEvent(event.postData).then(response => {
executePostFromPostEvent(event.postData, researchEventData).then(response => {
const { data } = response;
const {
header,

View File

@@ -54,7 +54,7 @@ function DatesBannerContainer({
{
name: 'resetDatesBanner',
shouldDisplay: resetDates,
clickHandler: () => dispatch(resetDeadlines(courseId, tabFetch)),
clickHandler: () => dispatch(resetDeadlines(courseId, model, tabFetch)),
},
];

View File

@@ -47,8 +47,9 @@ describe('Tab Page', () => {
const getTabDataMock = jest.fn(() => ({
type: 'MOCK_ACTION',
}));
const model = 'outline';
await executeThunk(thunks.resetDeadlines('courseId', getTabDataMock), testStore.dispatch);
await executeThunk(thunks.resetDeadlines('courseId', model, getTabDataMock), testStore.dispatch);
expect(screen.getByText('test-toast-header')).toBeInTheDocument();
expect(screen.getByText('test-toast-body')).toBeInTheDocument();