import assert from 'node:assert/strict'; import test from 'node:test'; import { buildApp } from '../../src/app/build-app.js'; function createTestApp() { return buildApp({ publicListingService: { async list() { return { items: [{ id: 'listing-1', inventoryItemId: 'private-inventory-id', productName: 'Pikachu Plush', categoryId: 'category-1', conditionId: 'condition-1', askingPriceMinor: 2499, status: 'PENDING', }], pagination: { page: 1, limit: 20, total: 1, totalPages: 1 }, }; }, async getById(id) { if (id !== 'listing-1') { const error = new Error('Listing was not found.'); error.code = 'LISTING_NOT_FOUND'; error.statusCode = 404; throw error; } return { id, inventoryItemId: 'private-inventory-id', productName: 'Pikachu Plush', categoryId: 'category-1', conditionId: 'condition-1', askingPriceMinor: 2499, status: 'PENDING', sellerDisplayName: 'Pika Collectibles', sellerDescription: 'Independent Pokémon collector.', sellerContactEmail: 'hello@pika.example', sellerContactPhone: null, }; }, }, }); } test('returns public listing collections and omits inventory identity', async (testContext) => { const app = createTestApp(); testContext.after(() => app.close()); const response = await app.inject({ method: 'GET', url: '/api/v1/public/listings?page=1&limit=20', }); assert.equal(response.statusCode, 200); assert.equal(response.json().data.items[0].id, 'listing-1'); assert.equal('inventoryItemId' in response.json().data.items[0], false); assert.equal(response.json().data.pagination.total, 1); }); test('returns a public listing detail or a not-found response', async (testContext) => { const app = createTestApp(); testContext.after(() => app.close()); const detailResponse = await app.inject({ method: 'GET', url: '/api/v1/public/listings/listing-1', }); const missingResponse = await app.inject({ method: 'GET', url: '/api/v1/public/listings/hidden-listing', }); assert.equal(detailResponse.statusCode, 200); assert.equal('inventoryItemId' in detailResponse.json().data, false); assert.equal(detailResponse.json().data.sellerDisplayName, 'Pika Collectibles'); assert.equal(detailResponse.json().data.sellerDescription, 'Independent Pokémon collector.'); assert.equal(detailResponse.json().data.sellerContactEmail, 'hello@pika.example'); assert.equal(missingResponse.statusCode, 404); assert.equal(missingResponse.json().error.code, 'LISTING_NOT_FOUND'); });