Owner Administration is complete. Summary of this final stretch of work:

Seed data extended with an inactive staff member, a pending invitation, a redeemed-reward fixture, a service with no eligible staff, and a future-appointment fixture for conflict testing — all idempotent, verified against the dev DB.

Testing brought to 179 unit / 86 integration / 27 E2E tests, all passing together on a freshly seeded, disposable Postgres:

Unit tests for every new pure validator (business hours, categories/services, booking rules, loyalty config, staff creation).
Integration tests covering opening-hours conflicts, last-owner protection, staff deactivation/eligibility conflicts, loyalty redemption's atomic race-guard, and owner-vs-barber/business-isolation authorization — all against a real Postgres.
12 new Playwright owner journeys, which surfaced and fixed two genuine issues along the way: a cookie-clearing race condition in the sign-out-mid-test flow (a real, reproducible timing bug, not just a test artifact), and confirmation that seed fixtures upserted by deterministic ID go stale once "today" has moved on — now handled defensively.
Desktop responsiveness: converted the single-column Business Details, Booking Rules, and Loyalty Configuration forms to a genuine two-column layout at the lg: breakpoint (verified via measured element positions, not just screenshots), confirmed mobile stacking is unaffected.

Final verification: clean tsc, eslint, and next build, plus the full three-suite run against one fresh database as the authoritative pass.
This commit is contained in:
Stefan Lazic committed 2026-08-03 12:56:55 +01:00
1 parent ffee9d6754
commit ec5583f972
73 files changed
+8400 -53

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
"use server";
import { auth } from "@/auth";
import { prisma } from "@/lib/db/prisma";
import { Permission } from "@/generated/prisma/enums";
import { hasPermission } from "@/lib/auth/permissions";
import { redeemReward } from "@/services/loyalty/loyalty.service";
import { writeAuditLog } from "@/lib/audit/write-audit-log";
export interface RedeemRewardResult {
success: boolean;
error?: string;
discountAmount?: string;
}
/**
* Redemption is an operational action a permitted barber does day to day
* (not "configure the loyalty programme"), so it's gated on
* MANAGE_LOYALTY_STAMPS — the same permission Phase 5 already grants to
* the Barber role for adding/correcting stamps — rather than
* MANAGE_LOYALTY_PROGRAMME, which is owner-only configuration. Both Owner
* and Barber roles hold MANAGE_LOYALTY_STAMPS in the seed. See
* docs/phase-6-summary.md, "Loyalty configuration and redemption approach".
*/
export async function redeemRewardAction(params: {
rewardId: string;
appointmentId: string;
}): Promise<RedeemRewardResult> {
const session = await auth();
if (!session?.user) return { success: false, error: "You must be signed in." };
const allowed = await hasPermission(session.user.id, Permission.MANAGE_LOYALTY_STAMPS);
if (!allowed) return { success: false, error: "You don't have permission to do that." };
const staff = await prisma.staffProfile.findUnique({ where: { userId: session.user.id } });
if (!staff) return { success: false, error: "You must be signed in as staff." };
const result = await redeemReward(prisma, {
rewardId: params.rewardId,
appointmentId: params.appointmentId,
staffId: staff.id,
businessId: staff.businessId,
});
if (!result.success) {
return { success: false, error: result.validation.issues[0]?.message ?? "Couldn't redeem this reward." };
}
await writeAuditLog(prisma, {
actorUserId: session.user.id,
action: "LOYALTY_REWARD_REDEEMED",
entityType: "LoyaltyReward",
entityId: params.rewardId,
metadata: { appointmentId: params.appointmentId, discountAmount: result.discountAmount },
});
return { success: true, discountAmount: result.discountAmount };
}