fix: paste guests, form errors, send feedback, check-in errors, invite recipients
Found by the manual e2e of the production build: - paste guests preview counted an array, so it read "[object Object]" and never offered Save guests; - New event and Add user errors now clear when the field is fixed; - "Send to all unsent" says when nothing was unsent; - the check-in lookup shows an error on an empty submit and carries the typed email or mobile into the walk-in form; - invitation emails sent over Pub/Sub now save their recipient's link, so the Emails page shows the recipient. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
4b1645ff64
commit
b4d36175d3
13 files changed
+206
-18
No files matched your search
@@ -0,0 +1,46 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||||
|
import { render, screen } from "@testing-library/react";
|
||||||
|
import userEvent from "@testing-library/user-event";
|
||||||
|
|
||||||
|
const mocks = vi.hoisted(() => ({ getCheckin: vi.fn(), lookupCheckin: vi.fn(), registerWalkIn: vi.fn() }));
|
||||||
|
vi.mock("@/app/lib/services/publicInvite", () => mocks);
|
||||||
|
vi.mock("next/navigation", () => ({ useParams: () => ({ token: "chk1" }) }));
|
||||||
|
|
||||||
|
import CheckinPage from "./page";
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mocks.getCheckin.mockReset().mockResolvedValue({
|
||||||
|
state: "OPEN", eventName: "Expo 2026", startDate: "2026-12-01", endDate: "2026-12-02", location: "KLCC", companyName: "INS",
|
||||||
|
notice: { id: 7, textEn: "We keep your data safe.", textMs: "Data anda selamat." }, interests: [],
|
||||||
|
});
|
||||||
|
mocks.lookupCheckin.mockReset().mockResolvedValue({ result: "FORM" });
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("/c/[token] lookup", () => {
|
||||||
|
it("shows a visible error and does not look up when the field is empty", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
render(<CheckinPage />);
|
||||||
|
await user.click(await screen.findByRole("button", { name: "Check in" }));
|
||||||
|
expect(await screen.findByText("Enter a mobile number or an email.")).toBeInTheDocument();
|
||||||
|
expect(screen.getByLabelText("Mobile number or email")).toHaveAttribute("aria-invalid", "true");
|
||||||
|
expect(mocks.lookupCheckin).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("carries a looked-up email into the walk-in form", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
render(<CheckinPage />);
|
||||||
|
await user.type(await screen.findByLabelText("Mobile number or email"), "w@b.co");
|
||||||
|
await user.click(screen.getByRole("button", { name: "Check in" }));
|
||||||
|
expect(await screen.findByLabelText("Email")).toHaveValue("w@b.co");
|
||||||
|
expect(screen.getByLabelText("Mobile number")).toHaveValue("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("carries a looked-up mobile into the walk-in form", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
render(<CheckinPage />);
|
||||||
|
await user.type(await screen.findByLabelText("Mobile number or email"), "0123456789");
|
||||||
|
await user.click(screen.getByRole("button", { name: "Check in" }));
|
||||||
|
expect(await screen.findByLabelText("Mobile number")).toHaveValue("0123456789");
|
||||||
|
expect(screen.getByLabelText("Email")).toHaveValue("");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -41,7 +41,10 @@ export default function CheckinPage() {
|
|||||||
|
|
||||||
async function lookup(e: FormEvent) {
|
async function lookup(e: FormEvent) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!value.trim()) return;
|
if (!value.trim()) {
|
||||||
|
setError(t("RegContactRequired"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
@@ -71,14 +74,14 @@ export default function CheckinPage() {
|
|||||||
if (phase === "welcome") body = <VisitorState icon={CheckCircle2} heading={firstName ? t("InviteWelcome", { name: firstName }) : t("InviteWelcomeAnon")} role="status" />;
|
if (phase === "welcome") body = <VisitorState icon={CheckCircle2} heading={firstName ? t("InviteWelcome", { name: firstName }) : t("InviteWelcomeAnon")} role="status" />;
|
||||||
else if (phase === "done") body = <VisitorState icon={CheckCircle2} heading={t("ChkDone", { event: open.eventName })} role="status" />;
|
else if (phase === "done") body = <VisitorState icon={CheckCircle2} heading={t("ChkDone", { event: open.eventName })} role="status" />;
|
||||||
else if (phase === "form") {
|
else if (phase === "form") {
|
||||||
body = <RegistrationForm tooManyKey="InviteTooMany" info={open} submit={(b) => registerWalkIn(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />;
|
body = <RegistrationForm tooManyKey="InviteTooMany" info={open} initial={value.includes("@") ? { email: value.trim() } : { mobile: value.trim() }} submit={(b) => registerWalkIn(token, b)} onDone={() => setPhase("done")} onInactive={() => setPhase("inactive")} />;
|
||||||
} else {
|
} else {
|
||||||
body = (
|
body = (
|
||||||
<form onSubmit={lookup} className="space-y-4" noValidate>
|
<form onSubmit={lookup} className="space-y-4" noValidate>
|
||||||
{error && <p role="alert" className="text-sm text-destructive">{error}</p>}
|
{error && <p role="alert" className="text-sm text-destructive">{error}</p>}
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<Label htmlFor="chk-value">{t("ChkLookup")}</Label>
|
<Label htmlFor="chk-value">{t("ChkLookup")}</Label>
|
||||||
<Input id="chk-value" className="h-11" value={value} onChange={(e) => setValue(e.target.value)} disabled={busy} />
|
<Input id="chk-value" className="h-11" value={value} onChange={(e) => setValue(e.target.value)} disabled={busy} aria-invalid={!!error} />
|
||||||
</div>
|
</div>
|
||||||
<Button type="submit" className="h-11 w-full" disabled={busy}>{t("InviteCheckin")}</Button>
|
<Button type="submit" className="h-11 w-full" disabled={busy}>{t("InviteCheckin")}</Button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { render, screen, waitFor } from "@testing-library/react";
|
||||||
|
import userEvent from "@testing-library/user-event";
|
||||||
|
import { describe, it, expect, vi } from "vitest";
|
||||||
|
|
||||||
|
vi.mock("@/app/lib/services/adminEvents", () => ({ listSalespersonOptions: vi.fn().mockResolvedValue([]) }));
|
||||||
|
|
||||||
|
import { EventForm } from "./EventForm";
|
||||||
|
import { pickDate } from "@/test/pickDate";
|
||||||
|
|
||||||
|
describe("EventForm error clearing", () => {
|
||||||
|
it("clears a field's error as soon as that field is filled", async () => {
|
||||||
|
render(<EventForm onSubmit={vi.fn()} />);
|
||||||
|
await userEvent.click(screen.getByRole("button", { name: /create/i }));
|
||||||
|
expect(await screen.findByText("Name is required.")).toBeInTheDocument();
|
||||||
|
|
||||||
|
await userEvent.type(screen.getByLabelText("Name"), "A");
|
||||||
|
expect(screen.queryByText("Name is required.")).not.toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Location is required.")).toBeInTheDocument();
|
||||||
|
|
||||||
|
pickDate("Start date", "2026-12-10");
|
||||||
|
await waitFor(() => expect(screen.queryByText("Start date is required.")).not.toBeInTheDocument());
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -59,6 +59,9 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) {
|
|||||||
const [pickersError, setPickersError] = useState<string | null>(null);
|
const [pickersError, setPickersError] = useState<string | null>(null);
|
||||||
|
|
||||||
const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({});
|
const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({});
|
||||||
|
// A field's error goes away as soon as the user edits that field; the next submit re-validates.
|
||||||
|
const clearError = (k: string) => setFieldErrors((e) => (k in e ? Object.fromEntries(Object.entries(e).filter(([f]) => f !== k)) : e));
|
||||||
|
|
||||||
const [formError, setFormError] = useState<string | null>(null);
|
const [formError, setFormError] = useState<string | null>(null);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
|
||||||
@@ -197,6 +200,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) {
|
|||||||
value={companyChoice}
|
value={companyChoice}
|
||||||
onValueChange={(v) => {
|
onValueChange={(v) => {
|
||||||
setCompanyChoice(v);
|
setCompanyChoice(v);
|
||||||
|
clearError("company");
|
||||||
setSelectedIds(new Set()); // the team is company-specific
|
setSelectedIds(new Set()); // the team is company-specific
|
||||||
}}
|
}}
|
||||||
disabled={saving}
|
disabled={saving}
|
||||||
@@ -224,7 +228,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) {
|
|||||||
id="evt-name"
|
id="evt-name"
|
||||||
required
|
required
|
||||||
value={name}
|
value={name}
|
||||||
onChange={(e) => setName(e.target.value)}
|
onChange={(e) => { setName(e.target.value); clearError("name"); }}
|
||||||
disabled={saving}
|
disabled={saving}
|
||||||
aria-invalid={!!fieldErrors.name}
|
aria-invalid={!!fieldErrors.name}
|
||||||
/>
|
/>
|
||||||
@@ -241,7 +245,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) {
|
|||||||
id="evt-location"
|
id="evt-location"
|
||||||
required
|
required
|
||||||
value={location}
|
value={location}
|
||||||
onChange={(e) => setLocation(e.target.value)}
|
onChange={(e) => { setLocation(e.target.value); clearError("location"); }}
|
||||||
disabled={saving}
|
disabled={saving}
|
||||||
aria-invalid={!!fieldErrors.location}
|
aria-invalid={!!fieldErrors.location}
|
||||||
/>
|
/>
|
||||||
@@ -257,7 +261,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) {
|
|||||||
<DatePicker
|
<DatePicker
|
||||||
id="evt-start"
|
id="evt-start"
|
||||||
value={startDate}
|
value={startDate}
|
||||||
onChange={setStartDate}
|
onChange={(v) => { setStartDate(v); clearError("startDate"); }}
|
||||||
aria-label={t("EvtStartDate")}
|
aria-label={t("EvtStartDate")}
|
||||||
required
|
required
|
||||||
disabled={saving}
|
disabled={saving}
|
||||||
@@ -275,7 +279,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) {
|
|||||||
<DatePicker
|
<DatePicker
|
||||||
id="evt-end"
|
id="evt-end"
|
||||||
value={endDate}
|
value={endDate}
|
||||||
onChange={setEndDate}
|
onChange={(v) => { setEndDate(v); clearError("endDate"); }}
|
||||||
aria-label={t("EvtEndDate")}
|
aria-label={t("EvtEndDate")}
|
||||||
required
|
required
|
||||||
disabled={saving}
|
disabled={saving}
|
||||||
@@ -312,7 +316,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) {
|
|||||||
type="number"
|
type="number"
|
||||||
min={1}
|
min={1}
|
||||||
value={capacity}
|
value={capacity}
|
||||||
onChange={(e) => setCapacity(e.target.value)}
|
onChange={(e) => { setCapacity(e.target.value); clearError("capacity"); }}
|
||||||
disabled={saving || !canSetLimits}
|
disabled={saving || !canSetLimits}
|
||||||
aria-invalid={!!fieldErrors.capacity}
|
aria-invalid={!!fieldErrors.capacity}
|
||||||
/>
|
/>
|
||||||
@@ -329,7 +333,7 @@ export function EventForm({ initial, onSubmit, submitLabel }: EventFormProps) {
|
|||||||
type="number"
|
type="number"
|
||||||
min={1}
|
min={1}
|
||||||
value={invitationCap}
|
value={invitationCap}
|
||||||
onChange={(e) => setInvitationCap(e.target.value)}
|
onChange={(e) => { setInvitationCap(e.target.value); clearError("invitationCap"); }}
|
||||||
disabled={saving || !canSetLimits}
|
disabled={saving || !canSetLimits}
|
||||||
aria-invalid={!!fieldErrors.invitationCap}
|
aria-invalid={!!fieldErrors.invitationCap}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { describe, it, expect, vi } from "vitest";
|
||||||
|
import { render, screen } from "@testing-library/react";
|
||||||
|
import userEvent from "@testing-library/user-event";
|
||||||
|
|
||||||
|
const mocks = vi.hoisted(() => ({
|
||||||
|
listGuests: vi.fn(),
|
||||||
|
addGuests: vi.fn(),
|
||||||
|
removeGuest: vi.fn(),
|
||||||
|
sendInvites: vi.fn(),
|
||||||
|
getAttendance: vi.fn(),
|
||||||
|
useAdminAuth: vi.fn(),
|
||||||
|
}));
|
||||||
|
vi.mock("@/app/lib/services/adminGuests", () => mocks);
|
||||||
|
vi.mock("@/app/lib/AdminAuthContext", () => ({ useAdminAuth: mocks.useAdminAuth }));
|
||||||
|
|
||||||
|
import { GuestsCard } from "./GuestsCard";
|
||||||
|
|
||||||
|
describe("GuestsCard send to all unsent", () => {
|
||||||
|
it("says so when nothing was sent or skipped", async () => {
|
||||||
|
mocks.listGuests.mockResolvedValue([]);
|
||||||
|
mocks.getAttendance.mockResolvedValue({});
|
||||||
|
mocks.sendInvites.mockResolvedValue({ sent: 0, skippedNoEmail: 0 });
|
||||||
|
mocks.useAdminAuth.mockReturnValue({ loading: false, hasModule: () => true });
|
||||||
|
render(<GuestsCard eventUuid="u1" />);
|
||||||
|
await userEvent.click(await screen.findByRole("button", { name: "Send to all unsent" }));
|
||||||
|
expect(await screen.findByRole("status")).toHaveTextContent("No unsent invitations");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -131,7 +131,7 @@ export function GuestsCard({ eventUuid, team = [] }: { eventUuid: string; team?:
|
|||||||
const send = (target: { guestIds: number[] } | { allUnsent: true }) =>
|
const send = (target: { guestIds: number[] } | { allUnsent: true }) =>
|
||||||
run(async () => {
|
run(async () => {
|
||||||
const res = await sendInvites(eventUuid, target);
|
const res = await sendInvites(eventUuid, target);
|
||||||
setNotice(t("GuestSendResult", { sent: res.sent, skipped: res.skippedNoEmail }));
|
setNotice(res.sent + res.skippedNoEmail === 0 ? t("GuestNoUnsent") : t("GuestSendResult", { sent: res.sent, skipped: res.skippedNoEmail }));
|
||||||
await load();
|
await load();
|
||||||
}, t("GuestSendFailed"));
|
}, t("GuestSendFailed"));
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { render, screen, waitFor } from "@testing-library/react";
|
||||||
|
import userEvent from "@testing-library/user-event";
|
||||||
|
import { describe, it, expect, vi } from "vitest";
|
||||||
|
|
||||||
|
vi.mock("@/app/lib/services/adminRoles", () => ({ listAdminRoles: vi.fn().mockResolvedValue([]) }));
|
||||||
|
vi.mock("@/app/lib/AdminAuthContext", () => ({ useAdminAuth: vi.fn().mockReturnValue({ id: null }) }));
|
||||||
|
|
||||||
|
import { UserForm } from "./UserForm";
|
||||||
|
|
||||||
|
describe("UserForm error clearing", () => {
|
||||||
|
it("clears a field's error as soon as that field is filled", async () => {
|
||||||
|
render(<UserForm onSubmit={vi.fn()} />);
|
||||||
|
await userEvent.click(screen.getByRole("button", { name: /save|create|add/i }));
|
||||||
|
expect(await screen.findByText("Name is required.")).toBeInTheDocument();
|
||||||
|
|
||||||
|
await userEvent.type(screen.getByLabelText("Name"), "A");
|
||||||
|
await waitFor(() => expect(screen.queryByText("Name is required.")).not.toBeInTheDocument());
|
||||||
|
expect(screen.getByText("Email is required.")).toBeInTheDocument();
|
||||||
|
await userEvent.type(screen.getByLabelText("Email"), "a@x.my");
|
||||||
|
expect(screen.queryByText("Email is required.")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -68,6 +68,9 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF
|
|||||||
const [loadingPickers, setLoadingPickers] = useState(true);
|
const [loadingPickers, setLoadingPickers] = useState(true);
|
||||||
|
|
||||||
const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({});
|
const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({});
|
||||||
|
// A field's error goes away as soon as the user edits that field; the next submit re-validates.
|
||||||
|
const clearError = (k: string) => setFieldErrors((e) => (k in e ? Object.fromEntries(Object.entries(e).filter(([f]) => f !== k)) : e));
|
||||||
|
|
||||||
const [formError, setFormError] = useState<string | null>(null);
|
const [formError, setFormError] = useState<string | null>(null);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
|
||||||
@@ -161,7 +164,7 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF
|
|||||||
id="user-name"
|
id="user-name"
|
||||||
required
|
required
|
||||||
value={name}
|
value={name}
|
||||||
onChange={(e) => setName(e.target.value)}
|
onChange={(e) => { setName(e.target.value); clearError("name"); }}
|
||||||
disabled={saving}
|
disabled={saving}
|
||||||
aria-invalid={!!fieldErrors.name}
|
aria-invalid={!!fieldErrors.name}
|
||||||
/>
|
/>
|
||||||
@@ -188,7 +191,7 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF
|
|||||||
id="user-username"
|
id="user-username"
|
||||||
required
|
required
|
||||||
value={username}
|
value={username}
|
||||||
onChange={(e) => setUsername(e.target.value)}
|
onChange={(e) => { setUsername(e.target.value); clearError("username"); }}
|
||||||
// The backend ignores username on update, so it is fixed once the user exists.
|
// The backend ignores username on update, so it is fixed once the user exists.
|
||||||
disabled={saving || initial?.id != null}
|
disabled={saving || initial?.id != null}
|
||||||
aria-invalid={!!fieldErrors.username}
|
aria-invalid={!!fieldErrors.username}
|
||||||
@@ -207,7 +210,7 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF
|
|||||||
type="email"
|
type="email"
|
||||||
required
|
required
|
||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => { setEmail(e.target.value); clearError("email"); }}
|
||||||
disabled={saving}
|
disabled={saving}
|
||||||
aria-invalid={!!fieldErrors.email}
|
aria-invalid={!!fieldErrors.email}
|
||||||
/>
|
/>
|
||||||
@@ -221,7 +224,7 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF
|
|||||||
{showCompany && (
|
{showCompany && (
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<Label htmlFor="user-company">{t("Company")}</Label>
|
<Label htmlFor="user-company">{t("Company")}</Label>
|
||||||
<Select value={company} onValueChange={(v) => setCompany(v)} disabled={saving}>
|
<Select value={company} onValueChange={(v) => { setCompany(v); clearError("company"); }} disabled={saving}>
|
||||||
<SelectTrigger id="user-company" aria-invalid={!!fieldErrors.company} className="w-full">
|
<SelectTrigger id="user-company" aria-invalid={!!fieldErrors.company} className="w-full">
|
||||||
<SelectValue placeholder={t("SelectCompany")} />
|
<SelectValue placeholder={t("SelectCompany")} />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
@@ -244,8 +247,8 @@ export function UserForm({ initial, onSubmit, submitLabel, withPassword }: UserF
|
|||||||
<PasswordFields
|
<PasswordFields
|
||||||
password={password}
|
password={password}
|
||||||
confirmPassword={confirmPassword}
|
confirmPassword={confirmPassword}
|
||||||
onPassword={setPassword}
|
onPassword={(v) => { setPassword(v); clearError("password"); }}
|
||||||
onConfirmPassword={setConfirmPassword}
|
onConfirmPassword={(v) => { setConfirmPassword(v); clearError("confirmPassword"); }}
|
||||||
disabled={saving}
|
disabled={saving}
|
||||||
passwordError={fieldErrors.password}
|
passwordError={fieldErrors.password}
|
||||||
confirmError={fieldErrors.confirmPassword}
|
confirmError={fieldErrors.confirmPassword}
|
||||||
|
|||||||
@@ -569,6 +569,7 @@ export const DEFAULT_MESSAGES: Record<string, string> = {
|
|||||||
GuestAddedCount: "Added {count}",
|
GuestAddedCount: "Added {count}",
|
||||||
GuestSendAll: "Send to all unsent",
|
GuestSendAll: "Send to all unsent",
|
||||||
GuestSendResult: "Sent {sent}, skipped {skipped} with no email",
|
GuestSendResult: "Sent {sent}, skipped {skipped} with no email",
|
||||||
|
GuestNoUnsent: "No unsent invitations",
|
||||||
GuestSendFailed: "Could not send the invites.",
|
GuestSendFailed: "Could not send the invites.",
|
||||||
GuestRegisteredRefused: "This guest has already registered and cannot be removed.",
|
GuestRegisteredRefused: "This guest has already registered and cannot be removed.",
|
||||||
GuestRemoveFailed: "Could not remove the guest.",
|
GuestRemoveFailed: "Could not remove the guest.",
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { describe, it, expect, vi } from "vitest";
|
||||||
|
|
||||||
|
const mocks = vi.hoisted(() => ({ apiGet: vi.fn(), apiPost: vi.fn(), apiDelete: vi.fn() }));
|
||||||
|
vi.mock("@/app/lib/clientApi", () => mocks);
|
||||||
|
|
||||||
|
import { addGuests } from "./adminGuests";
|
||||||
|
|
||||||
|
describe("addGuests result", () => {
|
||||||
|
it("turns the API's added guest list into a count", async () => {
|
||||||
|
// The mobile-api returns the added guests themselves, not a number.
|
||||||
|
mocks.apiPost.mockResolvedValue({ added: [{ name: "A" }, { name: "B" }], rejected: [] });
|
||||||
|
expect(await addGuests("e1", [], true)).toEqual({ added: 2, rejected: [] });
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -46,8 +46,11 @@ export interface Attendance {
|
|||||||
const base = (uuid: string) => `/api/events/${encodeURIComponent(uuid)}`;
|
const base = (uuid: string) => `/api/events/${encodeURIComponent(uuid)}`;
|
||||||
|
|
||||||
export const listGuests = (uuid: string) => apiGet<EventGuest[]>(`${base(uuid)}/guests`);
|
export const listGuests = (uuid: string) => apiGet<EventGuest[]>(`${base(uuid)}/guests`);
|
||||||
export const addGuests = (uuid: string, guests: GuestInput[], preview: boolean) =>
|
// The API lists the added guests; the screen only needs how many.
|
||||||
apiPost<AddGuestsResult>(`${base(uuid)}/guests${preview ? "?preview=true" : ""}`, { guests });
|
export const addGuests = async (uuid: string, guests: GuestInput[], preview: boolean): Promise<AddGuestsResult> => {
|
||||||
|
const res = await apiPost<{ added?: unknown[]; rejected: GuestRejection[] }>(`${base(uuid)}/guests${preview ? "?preview=true" : ""}`, { guests });
|
||||||
|
return { added: res.added?.length ?? 0, rejected: res.rejected };
|
||||||
|
};
|
||||||
export const removeGuest = (uuid: string, id: number) => apiDelete<unknown>(`${base(uuid)}/guests/${id}`);
|
export const removeGuest = (uuid: string, id: number) => apiDelete<unknown>(`${base(uuid)}/guests/${id}`);
|
||||||
export const sendInvites = (uuid: string, target: { guestIds: number[] } | { allUnsent: true }) =>
|
export const sendInvites = (uuid: string, target: { guestIds: number[] } | { allUnsent: true }) =>
|
||||||
apiPost<{ sent: number; skippedNoEmail: number }>(`${base(uuid)}/guests/send`, target);
|
apiPost<{ sent: number; skippedNoEmail: number }>(`${base(uuid)}/guests/send`, target);
|
||||||
|
|||||||
+2
@@ -38,6 +38,8 @@ public class EmailService {
|
|||||||
public Email save(Email email) {
|
public Email save(Email email) {
|
||||||
// A published email may carry "sender": null, which overrides the entity default; keep the column filled.
|
// A published email may carry "sender": null, which overrides the entity default; keep the column filled.
|
||||||
if (email.getSender() == null) email.setSender(com.solvway.services.email.constants.EmailConstant.EMAIL_SENDER);
|
if (email.getSender() == null) email.setSender(com.solvway.services.email.constants.EmailConstant.EMAIL_SENDER);
|
||||||
|
// Published emails arrive without the recipient back-reference, which would save email_id as NULL.
|
||||||
|
if (email.getRecipients() != null) email.getRecipients().forEach(r -> r.setEmail(email));
|
||||||
return emailRepository.save(email);
|
return emailRepository.save(email);
|
||||||
}
|
}
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
package com.solvway.services.email.service;
|
||||||
|
|
||||||
|
import com.solvway.services.email.model.Email;
|
||||||
|
import com.solvway.services.email.model.Recipient;
|
||||||
|
import com.solvway.services.email.repo.EmailRepository;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/** Found live: invitation emails arrive over Pub/Sub with recipients not linked to the email, so email_id was saved as NULL. */
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class EmailServiceRecipientLinkTest {
|
||||||
|
|
||||||
|
@Mock private EmailRepository emailRepository;
|
||||||
|
@InjectMocks private EmailService service;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void savedRecipientsPointBackAtTheEmail() {
|
||||||
|
when(emailRepository.save(any(Email.class))).thenAnswer(i -> i.getArgument(0));
|
||||||
|
Recipient recipient = new Recipient();
|
||||||
|
recipient.setRecipient("a@example.test");
|
||||||
|
Email email = new Email();
|
||||||
|
email.setRecipients(List.of(recipient));
|
||||||
|
|
||||||
|
service.save(email);
|
||||||
|
|
||||||
|
assertThat(ReflectionTestUtils.getField(recipient, "email")).isSameAs(email);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user