Skip to content

Commit

Permalink
feat: prevent to delete signup after event start_time
Browse files Browse the repository at this point in the history
  • Loading branch information
jorilindell committed Jun 26, 2024
1 parent b723014 commit ae0c257
Show file tree
Hide file tree
Showing 15 changed files with 777 additions and 77 deletions.
6 changes: 5 additions & 1 deletion public/locales/en/signup.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
"capacityInWaitingList_other": "Registration for this event is still possible, but there are only {{count}} seats left in the queue.",
"capacityInWaitingListNoLimit": "Registration for this event is still possible, but there are only seats left in the queue.",
"closed": "Registration for this event is currently closed. Please try again later.",
"closedWithEnrolmentTime": "Registration for this event opens on {{openingDate}} at {{openingTime}}."
"closedWithEnrolmentTime": "Registration for this event opens on {{openingDate}} at {{openingTime}}.",
"eventStarted": "The event has already started and registration cannot be cancelled.",
"hasPaymentCancellation": "The payment will be cancelled and cannot be modified.",
"hasPaymentRefund": "The payment will be refunded and cannot be modified.",
"insufficientPermissions": "You do not have the right to edit registration details."
}
}
6 changes: 5 additions & 1 deletion public/locales/fi/signup.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
"capacityInWaitingList_other": "Ilmoittautuminen tähän tapahtumaan on vielä mahdollista, mutta jonopaikkoja on jäljellä vain {{count}} kpl.",
"capacityInWaitingListNoLimit": "Ilmoittautuminen tähän tapahtumaan on vielä mahdollista, mutta vain jonopaikkoja on jäljellä.",
"closed": "Ilmoittautuminen tähän tapahtumaan on tällä hetkellä suljettu. Kokeile myöhemmin uudelleen.",
"closedWithEnrolmentTime": "Ilmoittautuminen tähän tapahtumaan avautuu {{openingDate}} klo {{openingTime}}."
"closedWithEnrolmentTime": "Ilmoittautuminen tähän tapahtumaan avautuu {{openingDate}} klo {{openingTime}}.",
"eventStarted": "Tapahtuman on jo alkanut eikä ilmoittautumista voi perua.",
"hasPaymentCancellation": "Ilmoittautumisen maksua perutaan eikä sitä voi muokata.",
"hasPaymentRefund": "Ilmoittautumisen maksua hyvitetään eikä sitä voi muokata.",
"insufficientPermissions": "Sinulla ei ole oikeuksia muokata ilmoittautumisen tietoja."
}
}
6 changes: 5 additions & 1 deletion public/locales/sv/signup.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
"capacityInWaitingList_other": "Registrering för detta evenemang är fortfarande möjligt, men det är bara {{count}} platser kvar i kön.",
"capacityInWaitingListNoLimit": "Registrering till detta evenemang är fortfarande möjlig, men det finns endast platser kvar i kön.",
"closed": "Registreringen för detta evenemang är för närvarande stängd. Vänligen försök igen senare.",
"closedWithEnrolmentTime": "Anmälan till detta evenemang öppnar den {{openingDate}} kl {{openingTime}}."
"closedWithEnrolmentTime": "Anmälan till detta evenemang öppnar den {{openingDate}} kl {{openingTime}}.",
"eventStarted": "Evenemanget har redan börjat och registreringen kan inte avbrytas.",
"hasPaymentCancellation": "Registreringsavgiften kommer att annulleras och kan inte ändras.",
"hasPaymentRefund": "Anmälningsavgiften kommer att återbetalas och kan inte ändras.",
"insufficientPermissions": "Du har inte rätt att ändra dina registreringsuppgifter."
}
}
2 changes: 1 addition & 1 deletion src/domain/event/__mocks__/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const eventOverrides = {
offers: fakeOffers(1, [
{ is_free: false, price: fakeLocalisedObject('Event price') },
]),
start_time: new Date().toISOString(),
start_time: addDays(new Date(), 1).toISOString(),
};

export const locationText = [locationName, streetAddress, addressLocality].join(
Expand Down
19 changes: 19 additions & 0 deletions src/domain/event/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getEventAttributes,
getEventFields,
getEventLocationText,
isEventStarted,
} from '../utils';

afterEach(() => {
Expand Down Expand Up @@ -345,3 +346,21 @@ describe('downloadEventIcsFile', () => {
});
});
});

describe('isEventStarted', () => {
it.each([
[fakeEvent({ start_time: null }), false],
[fakeEvent({ start_time: '2023-05-01' }), true],
[fakeEvent({ start_time: '2024-04-01' }), true],
[fakeEvent({ start_time: '2024-04-30' }), true],
[fakeEvent({ start_time: '2025-05-01' }), false],
[fakeEvent({ start_time: '2024-06-01' }), false],
[fakeEvent({ start_time: '2024-05-02' }), false],
])(
'should return true if event is not started',
async (event, expectedResult) => {
advanceTo('2024-05-01');
expect(isEventStarted(event)).toBe(expectedResult);
}
);
});
6 changes: 6 additions & 0 deletions src/domain/event/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AxiosError } from 'axios';
import isPast from 'date-fns/isPast';
import { DateArray, DateTime, EventAttributes, createEvents } from 'ics';
import { TFunction } from 'next-i18next';

Expand Down Expand Up @@ -187,3 +188,8 @@ export const eventPathBuilder = ({

return `/event/${id}/${query}`;
};

export const isEventStarted = (event: Event): boolean => {
const startTime = event.start_time ? new Date(event.start_time) : null;
return startTime ? isPast(startTime) : false;
};
13 changes: 12 additions & 1 deletion src/domain/registration/__mocks__/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import addDays from 'date-fns/addDays';
import subDays from 'date-fns/subDays';

import {
fakeEvent,
fakeRegistration,
fakeRegistrationPriceGroup,
} from '../../../utils/mockDataUtils';
Expand Down Expand Up @@ -65,5 +66,15 @@ const registrationWithPriceGroup = fakeRegistration({
}),
],
});
const registrationWithOnGoingEvent = fakeRegistration({
event: fakeEvent({
start_time: subDays(new Date(), 1).toISOString(),
}),
});

export { registration, registrationWithPriceGroup, registrationOverrides };
export {
registration,
registrationWithOnGoingEvent,
registrationWithPriceGroup,
registrationOverrides,
};
25 changes: 22 additions & 3 deletions src/domain/signup/__tests__/EditSignupPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import {
} from '../../../utils/testUtils';
import { ROUTES } from '../../app/routes/constants';
import { mockedLanguagesResponses } from '../../language/__mocks__/languages';
import { registration } from '../../registration/__mocks__/registration';
import {
registration,
registrationWithOnGoingEvent,
} from '../../registration/__mocks__/registration';
import { TEST_REGISTRATION_ID } from '../../registration/constants';
import { signupGroup } from '../../signupGroup/__mocks__/signupGroup';
import {
Expand Down Expand Up @@ -81,13 +84,14 @@ const mockedSignupGroupResponse = rest.get(
(req, res, ctx) => res(ctx.status(200), ctx.json(signupGroup))
);

const defaultMocks = [
const commonMocks = [
...mockedLanguagesResponses,
mockedUserResponse,
mockedRegistrationResponse,
mockedSignupResponse,
];

const defaultMocks = [...commonMocks, mockedRegistrationResponse];

const pushEditSignupRoute = (
registrationId: string,
query?: NextParsedUrlQuery
Expand Down Expand Up @@ -131,6 +135,21 @@ test('should cancel signup', async () => {
);
});

test('should disable cancel button if event is already started', async () => {
const mockedRegistrationWithOnGoingEventResponse = rest.get(
`*/registration/${TEST_REGISTRATION_ID}/`,
(req, res, ctx) =>
res(ctx.status(200), ctx.json(registrationWithOnGoingEvent))
);
setQueryMocks(...commonMocks, mockedRegistrationWithOnGoingEventResponse);
pushEditSignupRoute(TEST_REGISTRATION_ID);
renderComponent();

await findFirstNameInputs();
const cancelButton = await getSignupFormElement('cancelButton');
expect(cancelButton).toBeDisabled();
});

test('should show error message when cancelling signup fails', async () => {
setQueryMocks(
...defaultMocks,
Expand Down
Loading

0 comments on commit ae0c257

Please sign in to comment.