feat: add public search pagination

This commit is contained in:
2026-09-08 19:28:13 -04:00
parent 43f4f69894
commit 27fe6c6116
6 changed files with 134 additions and 18 deletions
@@ -125,6 +125,44 @@ test('lists the most recent draft entries for an inventory item', async () => {
assert.equal(listingsForItem[0].inventoryItemId, inventoryItem.id);
});
test('searches public listings with pagination and hides sold items by default', async () => {
const { category, condition, inventoryItem, product } = await createInventoryFixture();
await listingRepository.create({
inventoryItemId: inventoryItem.id,
productName: product.name,
categoryId: category.id,
conditionId: condition.id,
askingPriceMinor: 2499,
status: 'PENDING',
});
const visible = await listingRepository.searchPublic({ page: 1, limit: 10 });
assert.equal(visible.total, 1);
assert.equal(visible.items.length, 1);
assert.equal(visible.items[0].status, 'PENDING');
await database.db
.update(listings)
.set({ status: 'CLOSED' })
.where(sql`inventory_item_id = ${inventoryItem.id}`);
await database.db
.update(inventoryItems)
.set({ status: 'SOLD' })
.where(sql`id = ${inventoryItem.id}`);
const hidden = await listingRepository.searchPublic({ page: 1, limit: 10 });
assert.equal(hidden.total, 0);
const included = await listingRepository.searchPublic({
page: 1,
limit: 10,
includeSold: true,
});
assert.equal(included.total, 1);
assert.equal(included.items[0].status, 'CLOSED');
});
test('persists image metadata only for the owning seller and counts item images', async () => {
const { seller, inventoryItem } = await createInventoryFixture();
const image = await inventoryImageRepository.createForSeller({