feat: add public seller directory

This commit is contained in:
2026-09-08 19:36:13 -04:00
parent 206bb18da6
commit a76d777a6b
11 changed files with 152 additions and 2 deletions
@@ -8,9 +8,11 @@ import {
categories,
conditionProfiles,
conditions,
inventoryItems,
listings,
mfaMethods,
passwordResetTokens,
products,
securityAuditEvents,
sellers,
sessions,
@@ -23,6 +25,7 @@ import { createPasswordResetRepository } from '../../src/modules/auth/repositori
import { createMfaMethodRepository } from '../../src/modules/auth/repositories/mfa-method-repository.js';
import { createInventoryItemRepository } from '../../src/modules/inventory/repositories/inventory-item-repository.js';
import { createProductRepository } from '../../src/modules/products/repositories/product-repository.js';
import { createSellerRepository } from '../../src/modules/sellers/repositories/seller-repository.js';
const connectionString = process.env.TEST_DATABASE_URL;
@@ -36,6 +39,7 @@ if (!new URL(connectionString).pathname.endsWith('_test')) {
const database = createDatabase(connectionString);
const productRepository = createProductRepository(database.db);
const sellerRepository = createSellerRepository(database.db);
const inventoryItemRepository = createInventoryItemRepository(database.db);
const sessionRepository = createSessionRepository(database.db);
const passwordResetRepository = createPasswordResetRepository(database.db);
@@ -190,6 +194,33 @@ test('finds only products with active inventory and a public listing', async ()
assert.equal(await productRepository.findPublicBySlug(product.slug), null);
});
test('lists only sellers with publicly visible inventory', async () => {
const { seller, category, condition } = await createCatalogPrerequisites();
const [product] = await database.db.insert(products).values({
sellerId: seller.id,
categoryId: category.id,
name: 'Public Seller Product',
slug: 'public-seller-product',
}).returning();
const [inventoryItem] = await database.db.insert(inventoryItems).values({
productId: product.id,
conditionId: condition.id,
}).returning();
await database.db.insert(listings).values({
inventoryItemId: inventoryItem.id,
productName: product.name,
categoryId: category.id,
conditionId: condition.id,
askingPriceMinor: 1999,
status: 'AVAILABLE',
});
assert.deepEqual((await sellerRepository.listPublic()).map(({ id }) => id), [seller.id]);
await database.db.update(listings).set({ status: 'CLOSED' });
assert.deepEqual(await sellerRepository.listPublic(), []);
});
test('retrieves only non-revoked, non-expired sessions', async () => {
const { user, seller } = await createCatalogPrerequisites();
const tokenHash = 'a hashed session token';