2018-06-17 13:34:59 +02:00
|
|
|
import Search from '../../../src/lib/search';
|
2018-07-02 08:24:45 +02:00
|
|
|
import Config from '../../../src/lib/config';
|
2018-06-17 13:34:59 +02:00
|
|
|
import Storage from '../../../src/lib/storage';
|
2018-07-02 08:24:45 +02:00
|
|
|
|
2018-06-17 13:34:59 +02:00
|
|
|
let config_hash = require('../partials/config/index');
|
2018-07-02 08:24:45 +02:00
|
|
|
|
2017-04-10 22:00:41 +02:00
|
|
|
|
2018-06-17 13:34:59 +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', () => {
|
2018-04-21 18:36:06 +02:00
|
|
|
beforeAll(async function() {
|
2017-04-27 06:54:53 +02:00
|
|
|
let config = new Config(config_hash);
|
2017-04-10 22:00:41 +02:00
|
|
|
this.storage = new Storage(config);
|
2018-04-21 18:36:06 +02:00
|
|
|
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');
|
2018-10-05 12:31:57 +02:00
|
|
|
expect(result).toHaveLength(3);
|
2017-04-20 10:50:48 +02:00
|
|
|
});
|
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);
|
2017-04-23 20:02:26 +02:00
|
|
|
let result = Search.query('test6');
|
2018-10-05 12:31:57 +02:00
|
|
|
expect(result).toHaveLength(1);
|
|
|
|
Search.remove(item.name);
|
2017-04-23 20:02:26 +02:00
|
|
|
result = Search.query('test6');
|
2018-10-05 12:31:57 +02:00
|
|
|
expect(result).toHaveLength(0);
|
|
|
|
});
|
2017-04-20 10:50:48 +02:00
|
|
|
});
|