Skip to content

Commit

Permalink
fix: remove completedAt and completedBy when uncompleting an event
Browse files Browse the repository at this point in the history
  • Loading branch information
simonadomnisoru committed Nov 4, 2024
1 parent 567f9eb commit 51e4051
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const changeEnrollmentAndEventsStatus = () => (
const enrollment = body.enrollments && body.enrollments.find(e => e.enrollment === 'FZAa7j0muDj');
const eventToDelete = enrollment.events.find(e => e.programStage === 'eHvTba5ijAh');
const { events, ...rest } = enrollment;
const enrollmentToUpdate = { ...rest, status: 'ACTIVE' };
const enrollmentToUpdate = { ...rest, status: 'ACTIVE', completedAt: null, completedBy: null };

return cy
.buildApiUrl('tracker?async=false&importStrategy=UPDATE')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const changeEnrollmentAndEventsStatus = () => (
const enrollmentToUpdate = {
...enrollment,
status: 'ACTIVE',
events: [{ ...eventToUpdate, status: 'ACTIVE' }],
completedAt: null,
completedBy: null,
events: [{ ...eventToUpdate, status: 'ACTIVE', completedAt: null, completedBy: null }],
};

return cy
Expand Down
15 changes: 13 additions & 2 deletions cypress/e2e/WidgetsForEnrollmentPages/WidgetEnrollment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@ const changeEnrollmentAndEventsStatus = () => (
.then(url => cy.request(url))
.then(({ body }) => {
const enrollment = body.enrollments && body.enrollments.find(e => e.enrollment === 'qyx7tscVpVB');
const eventsToUpdate = enrollment.events.map(e => ({ ...e, status: 'ACTIVE' }));
const enrollmentToUpdate = { ...enrollment, status: 'ACTIVE', events: eventsToUpdate };
const eventsToUpdate = enrollment.events.map(e => ({
...e,
status: 'ACTIVE',
completedAt: null,
completedBy: null,
}));
const enrollmentToUpdate = {
...enrollment,
status: 'ACTIVE',
completedAt: null,
completedBy: null,
events: eventsToUpdate,
};

return cy
.buildApiUrl('tracker?async=false&importStrategy=UPDATE')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
import { buildUrlQueryString } from '../../../utils/routing/buildUrlQueryString';
import { newEventWidgetActionTypes } from '../../WidgetEnrollmentEventNew/Validated/validated.actions';
import { enrollmentEditEventActionTypes } from '../../Pages/EnrollmentEditEvent';
import { statusTypes } from '../../../events/statusTypes';

const getDataEntryId = (event): string => (
getScopeInfo(event?.programId)?.scopeType === scopeTypes.TRACKER_PROGRAM
Expand Down Expand Up @@ -106,9 +107,13 @@ export const saveEditedEventEpic = (action$: InputObservable, store: ReduxStore,
const formServerValues = formFoundation.convertValues(formClientValues, convertToServerValue);
const mainDataServerValues: Object = convertMainEventClientToServer(mainDataClientValues, minor);

if (mainDataServerValues.status === 'COMPLETED' && !prevEventMainData.completedAt) {
if (mainDataServerValues.status === statusTypes.COMPLETED && !prevEventMainData.completedAt) {
mainDataServerValues.completedAt = getFormattedStringFromMomentUsingEuropeanGlyphs(moment());
}
if (mainDataServerValues.status === statusTypes.ACTIVE) {
mainDataServerValues.completedAt = null;
mainDataServerValues.completedBy = null;
}

const { eventContainer: prevEventContainer } = state.viewEventPage.loadedValues;

Expand Down

0 comments on commit 51e4051

Please sign in to comment.