Files
pokemon-inventory/apps/api/tests/application/search-service.test.js
T

80 lines
1.7 KiB
JavaScript

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 {
items: [{ id: 'listing-1', status: 'AVAILABLE' }],
total: 21,
};
},
},
});
const result = await service.searchPublic({
query: ' Pikachu #199 / holo ',
category: ' Cards ',
minPriceMinor: 1000,
maxPriceMinor: 5000,
page: 2,
limit: 10,
});
assert.deepEqual(result, {
items: [{ id: 'listing-1', status: 'AVAILABLE' }],
pagination: {
page: 2,
limit: 10,
total: 21,
totalPages: 3,
},
});
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 { items: [filters], total: 1 };
},
},
});
const filters = await service.searchPublic({
query: 'charizard',
includeSold: true,
page: 1,
limit: 25,
});
assert.deepEqual(filters, {
items: [{
text: 'charizard',
page: 1,
limit: 25,
includeSold: true,
}],
pagination: {
page: 1,
limit: 25,
total: 1,
totalPages: 1,
},
});
});