An item used to be live on the storefront the instant it was created. Now it starts pending, and a customer sees it only once it is published. The migration changes the column default and nothing else. Backfilling would un-publish the entire live catalogue, which is the one thing it must not do. Hiding a pending item took four separate changes, not one, and that is the part worth knowing. The storefront's item routes had no status filter at all — sold items are listed and rendered with a Sold badge deliberately — so pending could not be expressed as one more optional filter. GET /api/items now carries an exclusion the caller cannot opt out of; GET /api/items/:id carries the same, because hiding an item from the list while still serving it by id would leave it reachable to anyone who kept a link; and GET /api/filters excludes pending from both aggregates it computes. That last one is the least obvious: a pending item would have inflated its tags' counts, so a customer would read "Rare (1)", filter by it, and be told nothing matches — and its price would have stretched the slider to a range no visible item occupies. The tag count is computed over the joined items rather than filtered with a WHERE. A WHERE would have dropped the row for a tag whose only item is pending, and the tag would have vanished from the drawer instead of showing zero. There is a test for exactly that, because the first version of this query had that bug. parseItemFilters is shared by the storefront and admin routes, so 'pending' parses on both. The public route refuses it explicitly rather than answering with an empty list, which would read as "no items match" instead of "you may not ask that". The storefront's URL reader is deliberately left not accepting it either, with a comment saying so, since a request guaranteed to fail is not worth constructing. Publishing is the existing mark-available: same transition, same UPDATE, so the admin UI labels that button "Publish" when the item is pending rather than adding a second endpoint that does the same thing. Unpublish is new and is not symmetrical — it is refused for a reserved item, which someone is holding in their cart right now, and for a sold one, which is a record of something that happened rather than a draft. Both refusals name their reason, and the buttons are hidden in those states so the refusal is not how you find out. Changing a column default has reach, and it surfaced eight test fixtures that silently depended on it. Each is now explicit about the status it wants rather than inheriting one — better practice regardless, and immune to the next default change. Two tests also used 'pending' as their example of an *unknown* status; both would have quietly become tautologies, so they now use one that is genuinely unknown. Verified: 98 unit, 160 integration and 94 end-to-end passing, the last on a freshly created container. One earlier run showed a single failure in favorites.spec.ts; it passes in isolation and on a clean container, and is the cross-spec interference already recorded against the suite rather than anything from this change. Refs #90 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
90 lines
3.7 KiB
TypeScript
90 lines
3.7 KiB
TypeScript
import { test, expect } from './fixtures';
|
|
|
|
const suffix = () => `p${Date.now().toString(36)}${Math.random().toString(36).slice(2, 7)}`;
|
|
|
|
async function createItem(page: import('@playwright/test').Page, name: string, price: string) {
|
|
const created = await page.request.post('/api/admin/items', {
|
|
multipart: { name, description: 'A preview subject', price, category_id: '', tags: '[]' }
|
|
});
|
|
expect(created.ok()).toBeTruthy();
|
|
const id = (await created.json()).id as number;
|
|
// New items are pending. Published here so the card renders the same states
|
|
// a customer would see; the pending case is covered in the pending spec.
|
|
const published = await page.request.post(`/api/admin/items/${id}/mark-available`);
|
|
expect(published.ok()).toBeTruthy();
|
|
return id;
|
|
}
|
|
|
|
test.describe('Admin item preview', () => {
|
|
test('opens the storefront card from the item name', async ({ page }) => {
|
|
const name = `Preview ${suffix()}`;
|
|
await createItem(page, name, '42');
|
|
|
|
await page.goto('/admin');
|
|
await page.getByRole('button', { name }).click();
|
|
|
|
const drawer = page.getByRole('dialog', { name: `Preview: ${name}` });
|
|
await expect(drawer).toBeVisible();
|
|
|
|
// The card itself, not just an empty panel: the storefront renders the
|
|
// price formatted from cents, so this only passes if ItemCard rendered.
|
|
await expect(drawer.getByText('$42.00')).toBeVisible();
|
|
});
|
|
|
|
// The claim the preview has to make: it looks live, and it is not. The
|
|
// buttons must keep their normal appearance rather than being disabled,
|
|
// because showing a customer's view is the entire purpose of the panel.
|
|
test('shows the Add to Cart button in its normal enabled state', async ({ page }) => {
|
|
const name = `Preview ${suffix()}`;
|
|
await createItem(page, name, '15');
|
|
|
|
await page.goto('/admin');
|
|
await page.getByRole('button', { name }).click();
|
|
|
|
const drawer = page.getByRole('dialog', { name: `Preview: ${name}` });
|
|
const addToCart = drawer.getByRole('button', { name: 'Add to Cart' });
|
|
|
|
await expect(addToCart).toBeVisible();
|
|
await expect(addToCart).toBeEnabled();
|
|
});
|
|
|
|
// The assertion that matters, and the one a reviewer cannot make by looking
|
|
// at the screen. Signed out, a real Add to Cart opens the sign-in prompt
|
|
// before it can add anything — so if that modal never appears, the handler
|
|
// short-circuited before reaching any of its real work.
|
|
test('does not act when the preview card is clicked', async ({ page }) => {
|
|
const name = `Preview ${suffix()}`;
|
|
await createItem(page, name, '99');
|
|
|
|
await page.goto('/admin');
|
|
await page.getByRole('button', { name }).click();
|
|
|
|
const drawer = page.getByRole('dialog', { name: `Preview: ${name}` });
|
|
await drawer.getByRole('button', { name: 'Add to Cart' }).click();
|
|
|
|
// Nothing succeeded and nothing prompted.
|
|
await expect(page.getByText('Added to cart')).toHaveCount(0);
|
|
await expect(page.getByRole('dialog', { name: /sign in/i })).toHaveCount(0);
|
|
|
|
// And the drawer is still simply sitting there, unchanged.
|
|
await expect(drawer).toBeVisible();
|
|
await expect(drawer.getByRole('button', { name: 'Add to Cart' })).toBeEnabled();
|
|
});
|
|
|
|
// The storefront card must stay live where it is actually used, or this
|
|
// change would have quietly broken buying things.
|
|
test('leaves the real storefront card working', async ({ page }) => {
|
|
const name = `Live ${suffix()}`;
|
|
await createItem(page, name, '20');
|
|
|
|
await page.goto('/');
|
|
const card = page.locator('.ant-card').filter({ hasText: name });
|
|
await expect(card).toBeVisible();
|
|
|
|
await card.getByRole('button', { name: 'Add to Cart' }).click();
|
|
|
|
// Signed out, the real card prompts for sign-in — proof the handler ran.
|
|
await expect(page.getByRole('dialog')).toBeVisible();
|
|
});
|
|
});
|