0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00
verdaccio/packages/search-indexer/test/index.spec.ts
Juan Picado 87c16127b4
refactor: search package (#4489)
* refactor: search package

refactor: search package

* update deps

* refactor

* refactor tests

* add tests
2024-03-10 17:58:39 +01:00

47 lines
1.1 KiB
TypeScript

import { expect, test } from 'vitest';
import { Logger } from '@verdaccio/types';
import { SearchMemoryIndexer } from '../src';
class MockStore {
getLocalDatabase(cb) {
return cb(null, [
{
name: 'verdaccio-search',
version: '1.0.0',
readme: 'foo',
description: 'foo',
keywords: ['foo', 'bar'],
},
{
name: 'verdaccio-utils',
version: '2.0.0',
readme: 'foo',
description: 'foo',
keywords: 'some',
},
]);
}
}
const logger = {
// eslint-disable-next-line no-console
error: (...arg) => console.error(...arg),
} as Logger;
test('should search', async () => {
const store = new MockStore();
SearchMemoryIndexer.configureStorage(store);
await SearchMemoryIndexer.init(logger);
// @ts-expect-error
await SearchMemoryIndexer.add({
name: 'verdaccio',
version: '2.0.0',
readme: 'foo',
description: '',
});
const query = await SearchMemoryIndexer.query('verdaccio');
expect(query.hits.map((item) => item.id)).toEqual(['verdaccio', 'verdaccio-utils']);
});