2020-03-03 23:59:19 +01:00
|
|
|
import { Config } from '@verdaccio/config';
|
|
|
|
import { configExample } from '@verdaccio/mock';
|
|
|
|
import { setup } from '@verdaccio/logger';
|
|
|
|
|
2020-08-11 07:21:51 +02:00
|
|
|
import { Storage } from '../src';
|
2020-03-03 23:59:19 +01:00
|
|
|
import { SearchInstance } from '../src/search';
|
|
|
|
|
|
|
|
setup([]);
|
|
|
|
|
|
|
|
const 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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
describe('search', () => {
|
2020-08-13 23:27:00 +02:00
|
|
|
beforeAll(async function () {
|
2020-03-03 23:59:19 +01:00
|
|
|
const config = new Config(configExample());
|
|
|
|
const storage = new Storage(config);
|
|
|
|
await storage.init(config);
|
|
|
|
SearchInstance.configureStorage(storage);
|
2020-08-13 23:27:00 +02:00
|
|
|
packages.map(function (item) {
|
2020-03-03 23:59:19 +01:00
|
|
|
// @ts-ignore
|
|
|
|
SearchInstance.add(item);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('search query item', () => {
|
|
|
|
const result = SearchInstance.query('t');
|
|
|
|
expect(result).toHaveLength(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('search remove item', () => {
|
|
|
|
const item = {
|
|
|
|
name: 'test6',
|
|
|
|
description: 'description',
|
|
|
|
_npmUser: {
|
|
|
|
name: 'test_user',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
// @ts-ignore
|
|
|
|
SearchInstance.add(item);
|
|
|
|
let result = SearchInstance.query('test6');
|
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
SearchInstance.remove(item.name);
|
|
|
|
result = SearchInstance.query('test6');
|
|
|
|
expect(result).toHaveLength(0);
|
|
|
|
});
|
|
|
|
});
|