[#7] fixed move destination

This commit is contained in:
Camille Moussu
2025-08-29 10:21:43 +02:00
parent 8ce8839383
commit 64f3ff0aa4
5 changed files with 12 additions and 13 deletions
+2 -3
View File
@@ -79,15 +79,14 @@ describe("eventApi", () => {
(api as unknown as jest.Mock).mockReturnValue({ (api as unknown as jest.Mock).mockReturnValue({
json: jest.fn().mockResolvedValue(mockResponse), json: jest.fn().mockResolvedValue(mockResponse),
}); });
const result = await moveEvent(mockEvent); const result = await moveEvent(mockEvent, "newurl.ics");
expect(api).toHaveBeenCalledWith( expect(api).toHaveBeenCalledWith(
"dav/calendars/667037022b752d0026472254/667037022b752d0026472254/cal1.ics", "dav/calendars/667037022b752d0026472254/667037022b752d0026472254/cal1.ics",
expect.objectContaining({ expect.objectContaining({
method: "MOVE", method: "MOVE",
headers: { headers: {
destination: destination: "newurl.ics",
"/calendars/667037022b752d0026472254/667037022b752d0026472254/cal1.ics",
}, },
}) })
); );
@@ -796,7 +796,6 @@ describe("Event Full Display", () => {
await waitFor(() => { await waitFor(() => {
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
expect(mockOnClose).toHaveBeenCalledWith({}, "backdropClick");
}); });
const updatedEvent = spy.mock.calls[0][0].newEvent; const updatedEvent = spy.mock.calls[0][0].newEvent;
@@ -854,7 +853,6 @@ describe("Event Full Display", () => {
await waitFor(() => { await waitFor(() => {
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
expect(mockOnClose).toHaveBeenCalledWith({}, "backdropClick");
}); });
const updatedEvent = spy.mock.calls[0][0].newEvent; const updatedEvent = spy.mock.calls[0][0].newEvent;
@@ -912,7 +910,6 @@ describe("Event Full Display", () => {
await waitFor(() => { await waitFor(() => {
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
expect(mockOnClose).toHaveBeenCalledWith({}, "backdropClick");
}); });
const updatedEvent = spy.mock.calls[0][0].newEvent; const updatedEvent = spy.mock.calls[0][0].newEvent;
+3 -3
View File
@@ -94,9 +94,9 @@ export const putEventAsync = createAsyncThunk<
}); });
export const moveEventAsync = createAsyncThunk< export const moveEventAsync = createAsyncThunk<
{ calId: string; events: CalendarEvent[] }, // Return type { calId: string; events: CalendarEvent[] }, // Return type
{ cal: Calendars; newEvent: CalendarEvent } // Arg type { cal: Calendars; newEvent: CalendarEvent; newURL: string } // Arg type
>("calendars/moveEvent", async ({ cal, newEvent }) => { >("calendars/moveEvent", async ({ cal, newEvent, newURL }) => {
const response = await moveEvent(newEvent); const response = await moveEvent(newEvent, newURL);
const calEvents = (await getCalendar(cal.id, { const calEvents = (await getCalendar(cal.id, {
start: formatDateToYYYYMMDDTHHMMSS(new Date(newEvent.start)), start: formatDateToYYYYMMDDTHHMMSS(new Date(newEvent.start)),
end: formatDateToYYYYMMDDTHHMMSS( end: formatDateToYYYYMMDDTHHMMSS(
+2 -2
View File
@@ -16,11 +16,11 @@ export async function putEvent(event: CalendarEvent) {
return response; return response;
} }
export async function moveEvent(event: CalendarEvent) { export async function moveEvent(event: CalendarEvent, newUrl: string) {
const response = await api(`dav${event.URL}`, { const response = await api(`dav${event.URL}`, {
method: "MOVE", method: "MOVE",
headers: { headers: {
destination: event.URL, destination: newUrl,
}, },
}); });
return response; return response;
+5 -2
View File
@@ -132,7 +132,6 @@ export default function EventDisplayModal({
}; };
dispatch(putEventAsync({ cal: calendar, newEvent })); dispatch(putEventAsync({ cal: calendar, newEvent }));
onClose({}, "backdropClick");
} }
const handleSave = () => { const handleSave = () => {
@@ -176,7 +175,11 @@ export default function EventDisplayModal({
if (newCalId !== calId) { if (newCalId !== calId) {
dispatch( dispatch(
moveEventAsync({ cal: userPersonnalCalendars[calendarid], newEvent }) moveEventAsync({
cal: userPersonnalCalendars[calendarid],
newEvent,
newURL: `/calendars/${newCalId}/${event.uid}.ics`,
})
); );
} }
onClose({}, "backdropClick"); onClose({}, "backdropClick");