@remit/backend 0.0.135 → 0.0.136
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -597,3 +597,74 @@ describe("POST /calendar-suggestions/{suggestionId}/dismiss", () => {
|
|
|
597
597
|
);
|
|
598
598
|
});
|
|
599
599
|
});
|
|
600
|
+
|
|
601
|
+
describe("POST /calendar-suggestions/{suggestionId}/accept with corrections", () => {
|
|
602
|
+
test("answers not-found for a calendar on another account, before writing anything", async () => {
|
|
603
|
+
const stranger = anAccount();
|
|
604
|
+
const strangersCalendar = await client.calendarCollection.create({
|
|
605
|
+
accountConfigId: stranger.accountConfigId,
|
|
606
|
+
urlSegment: "default",
|
|
607
|
+
displayName: "Calendar",
|
|
608
|
+
});
|
|
609
|
+
const { accountConfigId, event } = anAccount();
|
|
610
|
+
const card = await putSuggestion(accountConfigId, "msg-edited-cross");
|
|
611
|
+
|
|
612
|
+
await assert.rejects(
|
|
613
|
+
() =>
|
|
614
|
+
acceptSuggestion(
|
|
615
|
+
contextOf({
|
|
616
|
+
params: { suggestionId: card.suggestionId },
|
|
617
|
+
requestBody: {
|
|
618
|
+
calendarId: strangersCalendar.calendarId,
|
|
619
|
+
event: { summary: "Quarterly review, moved" },
|
|
620
|
+
},
|
|
621
|
+
}),
|
|
622
|
+
event,
|
|
623
|
+
),
|
|
624
|
+
(error: unknown) => (error as { statusCode?: number }).statusCode === 404,
|
|
625
|
+
);
|
|
626
|
+
|
|
627
|
+
assert.deepEqual(
|
|
628
|
+
await client.calendarObject.listByCalendar(strangersCalendar.calendarId),
|
|
629
|
+
[],
|
|
630
|
+
);
|
|
631
|
+
const untouched = await client.calendarSuggestion.get(
|
|
632
|
+
accountConfigId,
|
|
633
|
+
card.suggestionId,
|
|
634
|
+
);
|
|
635
|
+
assert.equal(untouched.state, CalendarSuggestionState.Pending);
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
test("refuses a card the reader already declined", async () => {
|
|
639
|
+
const { accountConfigId, event } = anAccount();
|
|
640
|
+
const calendar = await client.calendarCollection.create({
|
|
641
|
+
accountConfigId,
|
|
642
|
+
urlSegment: "default",
|
|
643
|
+
displayName: "Calendar",
|
|
644
|
+
});
|
|
645
|
+
const card = await putSuggestion(accountConfigId, "msg-edited-declined");
|
|
646
|
+
await client.calendarSuggestion.settle(accountConfigId, card.suggestionId, {
|
|
647
|
+
state: CalendarSuggestionState.Declined,
|
|
648
|
+
acceptedCalendarObjectId: "",
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
await assert.rejects(
|
|
652
|
+
() =>
|
|
653
|
+
acceptSuggestion(
|
|
654
|
+
contextOf({
|
|
655
|
+
params: { suggestionId: card.suggestionId },
|
|
656
|
+
requestBody: {
|
|
657
|
+
calendarId: calendar.calendarId,
|
|
658
|
+
event: { summary: "Quarterly review, moved" },
|
|
659
|
+
},
|
|
660
|
+
}),
|
|
661
|
+
event,
|
|
662
|
+
),
|
|
663
|
+
(error: unknown) => (error as { statusCode?: number }).statusCode === 400,
|
|
664
|
+
);
|
|
665
|
+
assert.deepEqual(
|
|
666
|
+
await client.calendarObject.listByCalendar(calendar.calendarId),
|
|
667
|
+
[],
|
|
668
|
+
);
|
|
669
|
+
});
|
|
670
|
+
});
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
CalendarInviteAnswer as CalendarInviteAnswerValue,
|
|
3
3
|
CalendarSuggestionResponse,
|
|
4
|
+
UpdateCalendarEventInput,
|
|
4
5
|
} from "@remit/api-openapi-types";
|
|
5
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
acceptCalendarSuggestion,
|
|
8
|
+
correctCalendarSuggestion,
|
|
9
|
+
} from "@remit/calendar-service";
|
|
6
10
|
import {
|
|
7
11
|
type CalendarSuggestionItem,
|
|
8
12
|
type ICalendarSuggestionRepository,
|
|
@@ -30,6 +34,7 @@ import type {
|
|
|
30
34
|
MessageCalendarSuggestionOperationIds,
|
|
31
35
|
OperationHandler,
|
|
32
36
|
} from "../types.js";
|
|
37
|
+
import { pickEventUpdate } from "./calendar-event.js";
|
|
33
38
|
|
|
34
39
|
/**
|
|
35
40
|
* The raw invitation bytes stay on the server. A client renders the projected
|
|
@@ -255,10 +260,25 @@ export const CalendarSuggestionActionOperations: Record<
|
|
|
255
260
|
);
|
|
256
261
|
}
|
|
257
262
|
|
|
263
|
+
const { event: corrections } = context.request.requestBody as {
|
|
264
|
+
event?: UpdateCalendarEventInput;
|
|
265
|
+
};
|
|
266
|
+
const corrected =
|
|
267
|
+
corrections === undefined
|
|
268
|
+
? { ok: true as const, value: suggestion }
|
|
269
|
+
: await correctCalendarSuggestion(
|
|
270
|
+
suggestion,
|
|
271
|
+
pickEventUpdate(corrections),
|
|
272
|
+
collection.timezone,
|
|
273
|
+
);
|
|
274
|
+
if (!corrected.ok) {
|
|
275
|
+
throw new BadRequestError(corrected.error.message);
|
|
276
|
+
}
|
|
277
|
+
|
|
258
278
|
const accepted = await acceptCalendarSuggestion(client.calendarUnitOfWork, {
|
|
259
279
|
accountConfigId,
|
|
260
280
|
calendarId,
|
|
261
|
-
suggestion,
|
|
281
|
+
suggestion: corrected.value,
|
|
262
282
|
attendee: await accountEmailForMessage(client, suggestion.messageId),
|
|
263
283
|
answer,
|
|
264
284
|
});
|