0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-20 22:52:46 -05:00
verdaccio/test/unit/modules/search/search.spec.js

65 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-05-20 08:47:52 +02:00
import Search from '../../../../src/lib/search';
import Config from '../../../../src/lib/config';
import Storage from '../../../../src/lib/storage';
import buildConfig from '../../partials/config';
2018-07-02 08:24:45 +02:00
2017-04-10 22:00:41 +02:00
2019-05-20 08:47:52 +02:00
require('../../../../src/lib/logger').setup([]);
2017-04-10 22:00:41 +02:00
2017-04-19 21:15:28 +02:00
let packages = [
2017-04-10 22:00:41 +02:00
{
name: 'test1',
description: 'description',
_npmUser: {
name: 'test_user',
2017-04-19 21:15:28 +02:00
},
2017-04-10 22:00:41 +02:00
},
{
name: 'test2',
description: 'description',
_npmUser: {
name: 'test_user',
2017-04-19 21:15:28 +02:00
},
2017-04-10 22:00:41 +02:00
},
{
name: 'test3',
description: 'description',
_npmUser: {
name: 'test_user',
2017-04-19 21:15:28 +02:00
},
2017-04-17 16:10:21 +02:00
},
2017-04-19 21:15:28 +02:00
];
2017-04-10 22:00:41 +02:00
2017-11-01 17:47:20 +01:00
describe('search', () => {
beforeAll(async function() {
let config = new Config(buildConfig());
2017-04-10 22:00:41 +02:00
this.storage = new Storage(config);
await this.storage.init(config);
2017-04-10 22:00:41 +02:00
Search.configureStorage(this.storage);
packages.map(function(item) {
Search.add(item);
});
});
2017-11-01 17:47:20 +01:00
test('search query item', () => {
2017-04-19 21:15:28 +02:00
let result = Search.query('t');
expect(result).toHaveLength(3);
});
2017-04-10 22:00:41 +02:00
2017-11-01 17:47:20 +01:00
test('search remove item', () => {
2017-04-19 21:15:28 +02:00
let item = {
2017-04-10 22:00:41 +02:00
name: 'test6',
description: 'description',
_npmUser: {
name: 'test_user',
2017-04-19 21:15:28 +02:00
},
2017-04-10 22:00:41 +02:00
};
Search.add(item);
let result = Search.query('test6');
expect(result).toHaveLength(1);
Search.remove(item.name);
result = Search.query('test6');
expect(result).toHaveLength(0);
});
});