From 3f741a7d8622c562b96a2eed070438629379870d Mon Sep 17 00:00:00 2001 From: Clarence Date: Tue, 1 Dec 2026 23:26:21 +0800 Subject: [PATCH 1/4] feat(qkit-earn): make qkit-order stamps Free for every vendor Remove the Pro gate from the qkit-earn settings UI, the save action and qkit_earn_resolve_program (migration 0072). Bump to 0.6.4. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 6 ++++ README.md | 4 +-- package.json | 2 +- src/app/dashboard/README.md | 8 +++--- src/app/dashboard/profile/page.tsx | 12 ++++---- .../profile/profile-page.dom.test.tsx | 14 ---------- .../dashboard/qkit-earn-settings.dom.test.tsx | 21 ++------------ src/app/dashboard/qkit-earn-settings.tsx | 14 ---------- src/app/dashboard/settings-actions.ts | 11 +------- .../dashboard/settings-lifecycle.dom.test.tsx | 1 - supabase/migrations/0072_qkit_earn_free.sql | 28 +++++++++++++++++++ supabase/migrations/README.md | 3 +- supabase/tests/README.md | 2 +- supabase/tests/qkit-earn-offer.test.sql | 19 ++++++------- 14 files changed, 62 insertions(+), 83 deletions(-) create mode 100644 supabase/migrations/0072_qkit_earn_free.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ea284b3..7e3b3af1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to loopkit are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## [0.6.4] - 2026-12-01 + +### Changed + +- Stamps earned from qkit orders are now Free. The dashboard qkit setting no longer asks for Pro, `saveQkitEarnConfigAction` no longer checks the plan, and migration `0072` drops the `is_pro` check from `qkit_earn_resolve_program`, so a free vendor's stamp program shows on every qkit order by default too. The program-count limit and other Pro features are unchanged. Migration `0072` must be applied to hosted staging and prod by hand. + ## [0.6.3] - 2026-12-01 ### Changed diff --git a/README.md b/README.md index 0f815d06..5be92d67 100644 --- a/README.md +++ b/README.md @@ -390,8 +390,8 @@ flips it from a switch there (`src/app/dashboard/customer-notify-settings.tsx`, under RLS (`for all` own-row policy, not service-role-only). See `docs/superpowers/specs/2026-08-16-customer-notify-vendor-toggle-design.md`. -Separately, every Pro vendor with a stamp program shows it on qkit orders by default and can switch it off -(migration `0071`; a vendor with no `qkit_earn_config` row offers its oldest active stamp program) +Separately, every vendor with a stamp program (Free or Pro) shows it on qkit orders by default and can switch it off +(migrations `0071`, `0072`; a vendor with no `qkit_earn_config` row offers its oldest active stamp program) so customers can earn a stamp from a completed qkit order (`src/app/dashboard/qkit-earn-settings.tsx`) — this is a pull-model claim link, not push automation: qkit shows a stamp card on the diff --git a/package.json b/package.json index c0085f4b..0ab39737 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopkit", - "version": "0.6.3", + "version": "0.6.4", "private": true, "packageManager": "pnpm@11.10.0", "engines": { diff --git a/src/app/dashboard/README.md b/src/app/dashboard/README.md index 13da88f1..45dc0410 100644 --- a/src/app/dashboard/README.md +++ b/src/app/dashboard/README.md @@ -13,7 +13,7 @@ Shared controls and `cn` used by this folder's modules are imported from `@merqo - `stamp-actions.ts` — server actions that change a card: `stampAction` (`add_stamp`, `rewardReady` via `getProgress` so every type's engine decides), `adjustStampAction` (manual `±` correction with a required reason via `loopkit.adjust_stamp`, free-tier), `recordVisitAction` (engine play path for Lucky Tap/Sprout with a server-side roll and `record_visit_checked`), `redeemPlantAction` and `regenerateCardAction` (credential rotation that keeps progress) - `lookup-actions.ts` — read-only server actions: `resolveTokenAction` (scanned token to a `kind: "card" | "voucher"` result, falling back to `voucher_by_token` on a card miss) and `lookupAction` (a card's per-type progress by phone, no visit recorded) - `redeem-actions.ts` — server actions that redeem: `redeemAction` (resets a full card, then alerts the vendor on Telegram and the customer when `vendor_notify_settings` allows it; a missing row means on and notify failures never change the result), `redeemVoucherAction` (catalog-mode Points Club voucher via `redeem_voucher_by_token`, mapping `already_redeemed`/`expired` to friendly copy) and `applyPointsOffsetAction` (offset-mode points deduction returning the dollar figure) -- `settings-actions.ts` — vendor settings actions: `saveQkitEarnConfigAction` (Pro-gated qkit-order earn program) and `saveCustomerNotifySettingsAction` (customer redemption-notify toggle, not Pro-gated), both upserting on `vendor_id` +- `settings-actions.ts` — vendor settings actions: `saveQkitEarnConfigAction` (qkit-order earn program, Free for every vendor) and `saveCustomerNotifySettingsAction` (customer redemption-notify toggle, not Pro-gated), both upserting on `vendor_id` - `activity/` - `card-link.tsx` — client `CardLinkActions`: copy-link (`@merqo/ui`'s `CopyButton`, keeping the sonner toasts) and print-QR buttons for the shop QR block - `card.ts` — exports the shared `StampCard` type `{ id, phone, stamp_count }` used across actions and form components @@ -44,8 +44,8 @@ Shared controls and `cn` used by this folder's modules are imported from `@merqo - `referrals/` - `points-offset-form.dom.test.tsx` — jsdom tests for `PointsOffsetForm`: input defaults to the card's full balance and Apply calls through, Apply disables once the entered amount exceeds the card's balance - `points-offset-form.tsx` — client `PointsOffsetForm`: a small inline apply-points form (not an AlertDialog like `redeem-button.tsx`/`redeem-voucher/`'s confirm screen, since there's a number to pick here) — calls `applyPointsOffsetAction` and reports the updated card plus the dollar figure back to the caller for the vendor to apply manually at their own register -- `qkit-earn-settings.dom.test.tsx` — jsdom tests for `QkitEarnSettings`: the not-Pro note, the on-by-default switch and its every-qkit-order copy (never claiming the stamp is awarded automatically), the no-stamp-program note, and picking a program and toggling the switch -- `qkit-earn-settings.tsx` — client `QkitEarnSettings` form: switch + program picker that calls `saveQkitEarnConfigAction`, with a not-available note for non-Pro vendors. The stamp card shows on every qkit order by default (migration `0071`), and turning the switch off saves `enabled = false`. With no stamp program it shows a note to create one. Wrapped in `@merqo/ui`'s `ElevatedCard` +- `qkit-earn-settings.dom.test.tsx` — jsdom tests for `QkitEarnSettings`: the on-by-default switch and its every-qkit-order copy (never claiming the stamp is awarded automatically), the no-stamp-program note, and any vendor picking a program and toggling the switch +- `qkit-earn-settings.tsx` — client `QkitEarnSettings` form: switch + program picker that calls `saveQkitEarnConfigAction`. Free for every vendor. The stamp card shows on every qkit order by default (migration `0071`), and turning the switch off saves `enabled = false`. With no stamp program it shows a note to create one. Wrapped in `@merqo/ui`'s `ElevatedCard` - `redeem-button.dom.test.tsx` — jsdom test asserting `RedeemButton`'s confirm dialog shows the exact stamp count and carryover wording - `redeem-button.tsx` — client `RedeemButton`: ConfirmDialog-confirmed redeem control that calls `redeemAction` and reports the reset card back to the caller - `redeem-voucher/` @@ -86,7 +86,7 @@ Each page exports its own `metadata.title`, shown through the root `loopkit | %s card-link test pins the clipboard-failure copy. -`qkit-earn-settings.tsx` stays Pro-gated: the qkit stamp card is on for every Pro vendor with a stamp program until they switch it off. +`qkit-earn-settings.tsx` is Free: the qkit stamp card is on for every vendor with a stamp program until they switch it off. Dates and times on these pages render through `@merqo/ui`'s `formatDate`/`formatDateTime` (Singapore time). diff --git a/src/app/dashboard/profile/page.tsx b/src/app/dashboard/profile/page.tsx index cca522c8..b4433371 100644 --- a/src/app/dashboard/profile/page.tsx +++ b/src/app/dashboard/profile/page.tsx @@ -4,7 +4,7 @@ import { getVendorProfile } from "@/lib/vendor"; import { createServerClient } from "@/lib/supabase/server"; import { getOrCreateVendorProfile } from "@/lib/merqo-vendor-profile"; import { ProfileForm } from "@/app/dashboard/profile/profile-form"; -import { listPrograms, isPro } from "@/lib/program"; +import { listPrograms } from "@/lib/program"; import { QkitEarnSettings } from "@/app/dashboard/qkit-earn-settings"; import { CustomerNotifySettings } from "@/app/dashboard/customer-notify-settings"; import type { SocialLinks } from "@/lib/types"; @@ -18,10 +18,9 @@ export default async function ProfilePage() { const profile = await getVendorProfile(); const supabase = await createServerClient(); - const [programs, pro, qkitEarnConfigResult, notifySettingsResult] = + const [programs, qkitEarnConfigResult, notifySettingsResult] = await Promise.all([ listPrograms(), - isPro(), supabase .from("qkit_earn_config") .select("program_id, enabled") @@ -37,9 +36,9 @@ export default async function ProfilePage() { const qkitPrograms = programs.filter( (prog) => prog.type === "stamp" && prog.active, ); - // Mirrors qkit_earn_resolve_program: with no saved row a Pro vendor's oldest - // active stamp program is already on. - const defaultProgram = pro ? qkitPrograms[0] : undefined; + // Mirrors qkit_earn_resolve_program: with no saved row the oldest active + // stamp program is already on. + const defaultProgram = qkitPrograms[0]; let qkitCurrent: { programId: string; enabled: boolean } | null = null; if (qkitEarnConfig) { qkitCurrent = { @@ -99,7 +98,6 @@ export default async function ProfilePage() { name: prog.name, }))} current={qkitCurrent} - isPro={pro} />
diff --git a/src/app/dashboard/profile/profile-page.dom.test.tsx b/src/app/dashboard/profile/profile-page.dom.test.tsx index f90d9f83..911a46e7 100644 --- a/src/app/dashboard/profile/profile-page.dom.test.tsx +++ b/src/app/dashboard/profile/profile-page.dom.test.tsx @@ -19,7 +19,6 @@ vi.mock("@/lib/program", () => ({ { id: "p1", name: "Coffee Stamps", type: "stamp", active: true }, { id: "p2", name: "Lucky Wheel", type: "wheel" }, ]), - isPro: vi.fn(async () => true), })); const qkitMaybeSingle = vi.fn( async (): Promise<{ @@ -49,14 +48,12 @@ vi.mock("@/app/dashboard/qkit-earn-settings", () => ({ QkitEarnSettings: (props: { programs: { id: string; name: string }[]; current: { programId: string; enabled: boolean } | null; - isPro: boolean; }) => (
{props.programs.map((p) => p.name).join(",")} / current: {props.current ? `${props.current.programId}:${String(props.current.enabled)}` : "none"}{" "} - / pro:{String(props.isPro)}
), })); @@ -132,17 +129,6 @@ describe("ProfilePage", () => { ); }); - it("does not default the qkit stamp on for a non-Pro vendor", async () => { - const { isPro } = await import("@/lib/program"); - vi.mocked(isPro).mockResolvedValueOnce(false); - - render(await ProfilePage()); - - expect(screen.getByTestId("qkit-earn-settings")).toHaveTextContent( - "current:none / pro:false", - ); - }); - it("keeps the qkit stamp card off when the saved row says so", async () => { qkitMaybeSingle.mockResolvedValueOnce({ data: { program_id: "p1", enabled: false }, diff --git a/src/app/dashboard/qkit-earn-settings.dom.test.tsx b/src/app/dashboard/qkit-earn-settings.dom.test.tsx index 531599d5..56453e60 100644 --- a/src/app/dashboard/qkit-earn-settings.dom.test.tsx +++ b/src/app/dashboard/qkit-earn-settings.dom.test.tsx @@ -8,25 +8,11 @@ vi.mock("./settings-actions", () => ({ })); describe("QkitEarnSettings", () => { - it("shows a not-available note instead of the form when not Pro", () => { - render( - , - ); - expect(screen.getByText(/not available yet/i)).toBeInTheDocument(); - expect(screen.queryByRole("link")).not.toBeInTheDocument(); - expect(screen.queryByRole("combobox")).not.toBeInTheDocument(); - }); - it("says a stamp card shows on every qkit order and is not automatic", () => { render( , ); expect(screen.getByText(/shows on every qkit order/i)).toBeInTheDocument(); @@ -34,18 +20,17 @@ describe("QkitEarnSettings", () => { expect(screen.queryByText(/automatically/i)).not.toBeInTheDocument(); }); - it("asks a Pro vendor for a stamp program when there is none", () => { - render(); + it("asks a vendor for a stamp program when there is none", () => { + render(); expect(screen.getByText(/create a stamp program/i)).toBeInTheDocument(); expect(screen.queryByRole("switch")).not.toBeInTheDocument(); }); - it("lets a Pro vendor pick a program and enable it", () => { + it("lets any vendor pick a program and enable it", () => { render( , ); expect(screen.getByRole("combobox")).toBeInTheDocument(); diff --git a/src/app/dashboard/qkit-earn-settings.tsx b/src/app/dashboard/qkit-earn-settings.tsx index 5ce238b3..67e310f3 100644 --- a/src/app/dashboard/qkit-earn-settings.tsx +++ b/src/app/dashboard/qkit-earn-settings.tsx @@ -20,26 +20,12 @@ type Program = { id: string; name: string }; export function QkitEarnSettings({ programs, current, - isPro, }: { programs: Program[]; current: { programId: string; enabled: boolean } | null; - isPro: boolean; }) { const { pending, save } = useSaveSettings(saveQkitEarnConfigAction); - if (!isPro) { - return ( - -

- Let customers claim a stamp after completing a qkit order, they get a - link on their order page and enter their phone number to collect it. -

-

Qkit stamp earning is not available yet.

-
- ); - } - if (programs.length === 0) { return ( diff --git a/src/app/dashboard/settings-actions.ts b/src/app/dashboard/settings-actions.ts index ea4f9601..9537fcfc 100644 --- a/src/app/dashboard/settings-actions.ts +++ b/src/app/dashboard/settings-actions.ts @@ -2,7 +2,6 @@ import { revalidatePath } from "next/cache"; import { requireVendor } from "@/features/auth"; -import { isPro } from "@/lib/program"; import { createServerClient } from "@/lib/supabase/server"; import type { ActionResult } from "@merqo/ui/kit-api"; @@ -12,19 +11,11 @@ export type QkitEarnConfigResult = ActionResult<{ }>; // Vendor-owned setting: which stamp program (if any) earns a stamp when a -// customer completes a qkit order. Pro-gated, same tier check as the -// program-count limit (isPro from @/lib/program). +// customer completes a qkit order. Free for every vendor. export async function saveQkitEarnConfigAction( formData: FormData, ): Promise { const { user } = await requireVendor(); - const pro = await isPro(); - if (!pro) { - return { - success: false, - error: "Qkit stamp earning is not available yet.", - }; - } const enabled = formData.get("enabled") === "on"; const programId = String(formData.get("program_id") ?? ""); diff --git a/src/app/dashboard/settings-lifecycle.dom.test.tsx b/src/app/dashboard/settings-lifecycle.dom.test.tsx index 6adae8b2..f4f666b6 100644 --- a/src/app/dashboard/settings-lifecycle.dom.test.tsx +++ b/src/app/dashboard/settings-lifecycle.dom.test.tsx @@ -35,7 +35,6 @@ describe.each(["notify", "earn"] as const)( , ); } diff --git a/supabase/migrations/0072_qkit_earn_free.sql b/supabase/migrations/0072_qkit_earn_free.sql new file mode 100644 index 00000000..f00d4e1b --- /dev/null +++ b/supabase/migrations/0072_qkit_earn_free.sql @@ -0,0 +1,28 @@ +-- qkit-order stamps are Free: with no qkit_earn_config row, any vendor's oldest +-- active stamp program is offered, not only a Pro vendor's. Only the is_pro +-- check from 0071 is removed. +create or replace function loopkit.qkit_earn_resolve_program(p_vendor uuid) +returns uuid +language sql +stable +security definer +set search_path = '' +as $$ + select case + when exists (select 1 from loopkit.qkit_earn_config c where c.vendor_id = p_vendor) then ( + select p.id + from loopkit.qkit_earn_config c + join loopkit.programs p on p.id = c.program_id and p.vendor_id = c.vendor_id + where c.vendor_id = p_vendor and c.enabled and p.active and p.type = 'stamp' + ) + else ( + select p.id + from loopkit.programs p + where p.vendor_id = p_vendor and p.active and p.type = 'stamp' + order by p.created_at, p.id + limit 1 + ) + end; +$$; + +revoke all on function loopkit.qkit_earn_resolve_program(uuid) from public, anon, authenticated, service_role; diff --git a/supabase/migrations/README.md b/supabase/migrations/README.md index 8b9f2b80..a73409c7 100644 --- a/supabase/migrations/README.md +++ b/supabase/migrations/README.md @@ -81,6 +81,7 @@ exception. - `0068_drop_vendor_pro.sql`: drops `loopkit.vendor_pro`. Apply `0066` to `0068` together. - `0069_drop_pricing.sql`: drops `loopkit.pricing`; merqo owns plans and pricing. - `0070_drop_upgrade_requests.sql`: drops `loopkit.upgrade_requests`; the upgrade inbox is gone. -- `0071_qkit_earn_default_stamp.sql`: `loopkit.qkit_earn_resolve_program(uuid)` picks the program a qkit order stamps: the `qkit_earn_config` program while enabled, active and a stamp program, or with no row, for a Pro vendor (`loopkit.is_pro`), the vendor's oldest active stamp program. `qkit_earn_offer`, `qkit_earn_lookup` and `qkit_earn_commit` use it, so the stamp shows on every qkit order by default and `enabled = false` still turns it off. The offer adds `reward_label`, `stamps_goal` and `stamps_per_order` (always 1) and returns only `{enabled: false}` for vendors with no stamp program. +- `0071_qkit_earn_default_stamp.sql`: `loopkit.qkit_earn_resolve_program(uuid)` picks the program a qkit order stamps: the `qkit_earn_config` program while enabled, active and a stamp program, or with no row, the vendor's oldest active stamp program. `qkit_earn_offer`, `qkit_earn_lookup` and `qkit_earn_commit` use it, so the stamp shows on every qkit order by default and `enabled = false` still turns it off. The offer adds `reward_label`, `stamps_goal` and `stamps_per_order` (always 1) and returns only `{enabled: false}` for vendors with no stamp program. +- `0072_qkit_earn_free.sql`: qkit-order stamps are Free. `qkit_earn_resolve_program` drops the `loopkit.is_pro` check from 0071, so a vendor with no `qkit_earn_config` row defaults to its oldest active stamp program on any plan. Prepared audit migrations require database validation and rollout review before deployment. diff --git a/supabase/tests/README.md b/supabase/tests/README.md index 1cacd2bd..64f951aa 100644 --- a/supabase/tests/README.md +++ b/supabase/tests/README.md @@ -16,7 +16,7 @@ fixtures have not yet been executed in this checkout. - `customer-capability.test.sql` and `earn-customer-capability.test.sql` exercise customer and earn proofs; `retired-rpc-permissions.test.sql` checks retired RPC grants. -- `qkit-earn-offer.test.sql` checks that only the service role can call `qkit_earn_offer`, that it answers enabled, disabled and unknown vendors with the reward, goal and stamps-per-order keys, that a Pro vendor with no config row defaults to its oldest active stamp program while a non-Pro vendor offers nothing and cannot claim, that an explicit off stays off, that a claim with no config row works once per order, and that it exposes no customer data. +- `qkit-earn-offer.test.sql` checks that only the service role can call `qkit_earn_offer`, that it answers enabled, disabled and unknown vendors with the reward, goal and stamps-per-order keys, that a vendor with no config row, Pro or free, defaults to its oldest active stamp program and can claim, that an explicit off stays off, that a claim with no config row works once per order, and that it exposes no customer data. - `reward-rpc.test.sql`, `plant-redemption.test.sql` and `plant-redemption-parity.test.sql` exercise reward state and redemption contracts. - `anon-abuse-limits.test.sql` covers the `0064` limiter (grants, RLS, window counting) and the 5-per-day referral credit cap, including retry of a reserved guest, the cap resetting, a past window not carrying its count and out-of-range parameters being rejected. diff --git a/supabase/tests/qkit-earn-offer.test.sql b/supabase/tests/qkit-earn-offer.test.sql index 9eee3734..9fa512b9 100644 --- a/supabase/tests/qkit-earn-offer.test.sql +++ b/supabase/tests/qkit-earn-offer.test.sql @@ -70,12 +70,12 @@ select is( select is( loopkit.qkit_earn_offer('00620000-0000-0000-0000-000000000003'), '{"enabled": true, "program_name": "Oldest Club", "reward_label": "Free kopi", "stamps_goal": 6, "stamps_per_order": 1}'::jsonb, - 'a Pro vendor with no config row defaults on with the oldest active stamp program' + 'a vendor with no config row defaults on with the oldest active stamp program' ); select is( loopkit.qkit_earn_offer('00620000-0000-0000-0000-000000000005'), - '{"enabled": false}'::jsonb, - 'a non-Pro vendor with no config row offers nothing' + '{"enabled": true, "program_name": "Free Club", "reward_label": "Snack", "stamps_goal": 10, "stamps_per_order": 1}'::jsonb, + 'a free vendor with no config row defaults on with its stamp program' ); select is( loopkit.qkit_earn_offer('00620000-0000-0000-0000-000000000004'), @@ -104,11 +104,10 @@ select throws_ok( 'not configured', 'a vendor who turned earning off cannot be claimed against' ); -select throws_ok( - $$select loopkit.customer_qkit_earn_claim('00620000-0000-0000-0000-000000000103', '+6591110064', 'Guest', null)$$, - 'P0001', - 'not configured', - 'a non-Pro vendor with no config row cannot be claimed against' +select is( + (loopkit.customer_qkit_earn_claim('00620000-0000-0000-0000-000000000103', '+6591110064', 'Guest', null)->>'stamp_count')::int, + 1, + 'a free vendor with no config row can be claimed against' ); reset role; select is( @@ -118,8 +117,8 @@ select is( ); select is( (select count(*) from loopkit.qkit_earn_events), - 1::bigint, - 'reading offers writes nothing and the order is claimed once' + 2::bigint, + 'reading offers writes nothing and each order is claimed once' ); select * from finish(); From 8cc1167365f260623401338cec9ae94854cd3574 Mon Sep 17 00:00:00 2001 From: Clarence Date: Tue, 1 Dec 2026 23:37:30 +0800 Subject: [PATCH 2/4] test(qkit-earn): cover ungated save action Co-Authored-By: Claude Opus 5.5 --- test/app/README.md | 2 +- test/app/save-qkit-earn-config-action.test.ts | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/test/app/README.md b/test/app/README.md index 237fc481..0bd9db1a 100644 --- a/test/app/README.md +++ b/test/app/README.md @@ -15,7 +15,7 @@ Supabase clients and `@/lib` collaborators mocked via `vi.mock`/`vi.hoisted`. - `profile-actions.test.ts` — vendor `/profile` action: `saveStallName` call after `requireVendor` - Token resolution cases live in `dashboard-actions.test.ts` (importing from the split `stamp-actions`, `lookup-actions` and `redeem-actions` modules), including empty-input rejection without an RPC and card-to-voucher fallback - `save-customer-notify-settings-action.test.ts` — `saveCustomerNotifySettingsAction`: upserts `vendor_notify_settings.customer_telegram_notify_enabled` true/false depending on the submitted checkbox state (an unchecked checkbox submits no field at all, resolving to `false`), returns a generic error without throwing when the upsert fails -- `save-qkit-earn-config-action.test.ts` — `saveQkitEarnConfigAction`: a vendor whose plan lacks qkit stamp earning gets "Qkit stamp earning is not available yet." and nothing is written. +- `save-qkit-earn-config-action.test.ts` — `saveQkitEarnConfigAction`: any vendor can save the setting (no plan check) and a missing program is rejected without a write. - `save-program-action.test.ts` — `saveProgramAction`: create/update dispatch, free/Pro entitlement gate, RPC call shape; a free vendor is blocked (create or edit) from a non-stamp mechanic, a premium stamp style, or a custom stamp color, while a Pro vendor can save any of them - `serve-customer.test.tsx` — jsdom: the vendor Counter serve flow (stamp/record-visit/lookup/redeem-plant end to end; the cup-variant plant lookup asserts via `Cup`'s `data-cup-coffee` hook, not an implementation detail of its old stroked-outline shape; its fixture uses the current "Half Full" cup stage name, not the old "Quarter Full"). Since the scan-first recompose it mocks `@/app/dashboard/counter/scan-hero` (exposing the same two scan buttons the old `scan-button` mock did) and passes `ServeCustomer`'s `shopName`/`shopJoinQrSvg`/`shopJoinLink` props via a shared `shop` fixture at every render site diff --git a/test/app/save-qkit-earn-config-action.test.ts b/test/app/save-qkit-earn-config-action.test.ts index c0ad501b..37af620f 100644 --- a/test/app/save-qkit-earn-config-action.test.ts +++ b/test/app/save-qkit-earn-config-action.test.ts @@ -1,13 +1,11 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; -const { requireVendorMock, isProMock, upsertMock } = vi.hoisted(() => ({ +const { requireVendorMock, upsertMock } = vi.hoisted(() => ({ requireVendorMock: vi.fn(), - isProMock: vi.fn(), upsertMock: vi.fn(), })); vi.mock("@/features/auth", () => ({ requireVendor: requireVendorMock })); -vi.mock("@/lib/program", () => ({ isPro: isProMock })); vi.mock("next/cache", () => ({ revalidatePath: vi.fn() })); vi.mock("@/lib/supabase/server", () => ({ createServerClient: vi.fn(async () => ({ @@ -30,17 +28,22 @@ describe("saveQkitEarnConfigAction", () => { upsertMock.mockResolvedValue({ error: null }); }); - it("states the plan limit without asking the vendor to upgrade", async () => { - isProMock.mockResolvedValue(false); - + it("saves the setting for any vendor without a plan check", async () => { const res = await saveQkitEarnConfigAction( form({ enabled: "on", program_id: "p1" }), ); - expect(res).toEqual({ - success: false, - error: "Qkit stamp earning is not available yet.", - }); + expect(res.success).toBe(true); + expect(upsertMock).toHaveBeenCalledWith( + { vendor_id: "v1", program_id: "p1", enabled: true }, + { onConflict: "vendor_id" }, + ); + }); + + it("asks for a program before saving", async () => { + const res = await saveQkitEarnConfigAction(form({ enabled: "on" })); + + expect(res).toEqual({ success: false, error: "Pick a program first." }); expect(upsertMock).not.toHaveBeenCalled(); }); }); From 9a8a6e609399dd57e20cb75835a2b2639f30c455 Mon Sep 17 00:00:00 2001 From: Clarence Date: Tue, 1 Dec 2026 23:56:22 +0800 Subject: [PATCH 3/4] chore(qkit-earn): describe 0072 behaviour in its header Co-Authored-By: Claude Opus 5.5 --- supabase/migrations/0072_qkit_earn_free.sql | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/supabase/migrations/0072_qkit_earn_free.sql b/supabase/migrations/0072_qkit_earn_free.sql index f00d4e1b..ac80d8b7 100644 --- a/supabase/migrations/0072_qkit_earn_free.sql +++ b/supabase/migrations/0072_qkit_earn_free.sql @@ -1,6 +1,4 @@ --- qkit-order stamps are Free: with no qkit_earn_config row, any vendor's oldest --- active stamp program is offered, not only a Pro vendor's. Only the is_pro --- check from 0071 is removed. +-- With no config row, the oldest active stamp program is offered on any plan. create or replace function loopkit.qkit_earn_resolve_program(p_vendor uuid) returns uuid language sql From 08aa4257a4f2d6116d0b9c487f2efe82477825ae Mon Sep 17 00:00:00 2001 From: Clarence Date: Wed, 2 Dec 2026 00:32:42 +0800 Subject: [PATCH 4/4] docs(profile): note qkit stamp setting is free for every vendor Co-Authored-By: Claude Opus 5.5 --- src/app/dashboard/profile/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/dashboard/profile/README.md b/src/app/dashboard/profile/README.md index 4f8b38ae..7ed99855 100644 --- a/src/app/dashboard/profile/README.md +++ b/src/app/dashboard/profile/README.md @@ -47,3 +47,5 @@ profile-form.errors test pins the "Could not save" and "do not match" copy. This folder now imports its shared page and dialog components from `@merqo/ui` (v0.42.1) instead of local copies. - `loading.tsx` uses `ListSkeleton` from `@merqo/ui`. + +The qkit stamp setting is free for every vendor and defaults to the oldest active stamp program; the page no longer reads the plan.