feat: add public search service and routes
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { createSearchService } from '../../src/modules/search/services/search-service.js';
|
||||
|
||||
test('normalizes public search input and delegates to the repository with public visibility defaults', async () => {
|
||||
const calls = [];
|
||||
const service = createSearchService({
|
||||
listingRepository: {
|
||||
async searchPublic(filters) {
|
||||
calls.push(filters);
|
||||
return [{ id: 'listing-1', status: 'AVAILABLE' }];
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = await service.searchPublic({
|
||||
query: ' Pikachu #199 / holo ',
|
||||
category: ' Cards ',
|
||||
minPriceMinor: 1000,
|
||||
maxPriceMinor: 5000,
|
||||
page: 2,
|
||||
limit: 10,
|
||||
});
|
||||
|
||||
assert.deepEqual(result, [{ id: 'listing-1', status: 'AVAILABLE' }]);
|
||||
assert.deepEqual(calls, [{
|
||||
text: 'pikachu 199 holo',
|
||||
category: 'Cards',
|
||||
minPriceMinor: 1000,
|
||||
maxPriceMinor: 5000,
|
||||
page: 2,
|
||||
limit: 10,
|
||||
includeSold: false,
|
||||
}]);
|
||||
});
|
||||
|
||||
test('allows explicit public sold results and keeps the public filter defaults', async () => {
|
||||
const service = createSearchService({
|
||||
listingRepository: {
|
||||
async searchPublic(filters) {
|
||||
return filters;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const filters = await service.searchPublic({
|
||||
query: 'charizard',
|
||||
includeSold: true,
|
||||
page: 1,
|
||||
limit: 25,
|
||||
});
|
||||
|
||||
assert.deepEqual(filters, {
|
||||
text: 'charizard',
|
||||
page: 1,
|
||||
limit: 25,
|
||||
includeSold: true,
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user