0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-30 22:34:10 -05:00
verdaccio/test/unit/modules/search/search.spec.ts
Juan Picado 558fcafc71
build: format code prettier, enable ci (#2886)
* fix: format code prettier, enable ci

* chore: add trivago import prettier pluggin
2022-01-09 20:51:50 +01:00

87 lines
1.8 KiB
TypeScript

import Config from '../../../../src/lib/config';
import { setup } from '../../../../src/lib/logger';
import Search from '../../../../src/lib/search';
import Storage from '../../../../src/lib/storage';
import buildConfig from '../../partials/config';
setup([]);
let packages = [
{
name: 'test1',
description: 'description',
_npmUser: {
name: 'test_user',
},
},
{
name: 'test2',
description: 'description',
_npmUser: {
name: 'test_user',
},
},
{
name: 'test3',
description: 'description',
_npmUser: {
name: 'test_user',
},
},
{
name: '@verdaccio/scope',
description: 'scope',
_npmUser: {
name: 'scope_user',
},
},
{
name: '@any/scope',
description: 'scope',
_npmUser: {
name: 'scope_user',
},
},
];
describe('search', () => {
beforeAll(async function () {
let config = new Config(buildConfig());
const storage = new Storage(config);
await storage.init(config);
Search.configureStorage(storage);
packages.map(function (item) {
// @ts-ignore
Search.add(item);
});
});
test('search query item', () => {
let result = Search.query('t');
expect(result).toHaveLength(3);
});
test('search query with @scope', () => {
let result = Search.query('@');
expect(result).toHaveLength(2);
result = Search.query('@verdaccio');
expect(result).toHaveLength(1);
});
test('search remove item', () => {
let item = {
name: 'test6',
description: 'description',
_npmUser: {
name: 'test_user',
},
};
// @ts-ignore
Search.add(item);
let result = Search.query('test6');
expect(result).toHaveLength(1);
Search.remove(item.name);
result = Search.query('test6');
expect(result).toHaveLength(0);
});
});