Quality / test (push) Canceled after 0s
Add public condition lookup options, condition filtering, and stable price/recent sorting with URL-backed catalog controls.
76 lines
2.6 KiB
JavaScript
76 lines
2.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import { buildApp } from '../../src/app/build-app.js';
|
|
|
|
test('returns public search results with pagination metadata', async (testContext) => {
|
|
const app = buildApp({
|
|
searchService: {
|
|
async searchPublic(filters) {
|
|
assert.equal(filters.page, 2);
|
|
assert.equal(filters.limit, 5);
|
|
assert.equal(filters.includeSold, true);
|
|
assert.equal(filters.sort, 'price_low');
|
|
assert.equal(filters.conditionId, 'condition-1');
|
|
return {
|
|
items: [{ id: 'listing-1', status: 'CLOSED' }],
|
|
pagination: { page: 2, limit: 5, total: 6, totalPages: 2 },
|
|
};
|
|
},
|
|
},
|
|
});
|
|
testContext.after(() => app.close());
|
|
|
|
const response = await app.inject({
|
|
method: 'GET',
|
|
url: '/api/v1/public/search?query=charizard&page=2&limit=5&includeSold=true&sort=price_low&conditionId=condition-1',
|
|
});
|
|
|
|
assert.equal(response.statusCode, 200);
|
|
assert.deepEqual(response.json().data.pagination, {
|
|
page: 2,
|
|
limit: 5,
|
|
total: 6,
|
|
totalPages: 2,
|
|
});
|
|
assert.equal(response.json().data.items[0].id, 'listing-1');
|
|
});
|
|
|
|
test('rejects malformed numeric search filters', async (testContext) => {
|
|
const app = buildApp({ searchService: { async searchPublic() { throw new Error('should not run'); } } });
|
|
testContext.after(() => app.close());
|
|
|
|
const response = await app.inject({
|
|
method: 'GET',
|
|
url: '/api/v1/public/search?minPriceMinor=12.5',
|
|
});
|
|
|
|
assert.equal(response.statusCode, 400);
|
|
assert.equal(response.json().error.code, 'INVALID_SEARCH_FILTER');
|
|
});
|
|
|
|
test('returns active public category options', async (testContext) => {
|
|
const app = buildApp({
|
|
catalogLookupRepository: {
|
|
async listCategories() { return [{ id: 'category-1', name: 'Trading Cards' }]; },
|
|
},
|
|
});
|
|
testContext.after(() => app.close());
|
|
|
|
const response = await app.inject({ method: 'GET', url: '/api/v1/public/lookups/categories' });
|
|
assert.equal(response.statusCode, 200);
|
|
assert.deepEqual(response.json().data, [{ id: 'category-1', name: 'Trading Cards' }]);
|
|
});
|
|
|
|
test('returns public condition options without category internals', async (testContext) => {
|
|
const app = buildApp({
|
|
catalogLookupRepository: {
|
|
async listConditions() { return [{ id: 'condition-1', name: 'Near Mint', code: 'NM', categoryId: 'private-category' }]; },
|
|
},
|
|
});
|
|
testContext.after(() => app.close());
|
|
|
|
const response = await app.inject({ method: 'GET', url: '/api/v1/public/lookups/conditions' });
|
|
assert.equal(response.statusCode, 200);
|
|
assert.deepEqual(response.json().data, [{ id: 'condition-1', name: 'Near Mint', code: 'NM' }]);
|
|
}); |