2017-04-19 14:15:28 -05:00
|
|
|
|
2017-12-22 15:32:52 -05:00
|
|
|
|
|
|
|
import assert from 'assert';
|
|
|
|
import Search from '../../src/lib/search';
|
|
|
|
import Storage from '../../src/lib/storage';
|
2017-04-19 14:15:28 -05:00
|
|
|
let config_hash = require('./partials/config');
|
2017-06-21 12:02:52 -05:00
|
|
|
let Config = require('../../src/lib/config');
|
2017-04-10 15:00:41 -05:00
|
|
|
|
2017-06-21 12:02:52 -05:00
|
|
|
require('../../src/lib/logger').setup([]);
|
2017-04-10 15:00:41 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
let packages = [
|
2017-04-10 15:00:41 -05:00
|
|
|
{
|
|
|
|
name: 'test1',
|
|
|
|
description: 'description',
|
|
|
|
_npmUser: {
|
|
|
|
name: 'test_user',
|
2017-04-19 14:15:28 -05:00
|
|
|
},
|
2017-04-10 15:00:41 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'test2',
|
|
|
|
description: 'description',
|
|
|
|
_npmUser: {
|
|
|
|
name: 'test_user',
|
2017-04-19 14:15:28 -05:00
|
|
|
},
|
2017-04-10 15:00:41 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'test3',
|
|
|
|
description: 'description',
|
|
|
|
_npmUser: {
|
|
|
|
name: 'test_user',
|
2017-04-19 14:15:28 -05:00
|
|
|
},
|
2017-04-17 09:10:21 -05:00
|
|
|
},
|
2017-04-19 14:15:28 -05:00
|
|
|
];
|
2017-04-10 15:00:41 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
describe('search', () => {
|
2018-04-21 11:36:06 -05:00
|
|
|
beforeAll(async function() {
|
2017-04-26 23:54:53 -05:00
|
|
|
let config = new Config(config_hash);
|
2017-04-10 15:00:41 -05:00
|
|
|
this.storage = new Storage(config);
|
2018-04-21 11:36:06 -05:00
|
|
|
await this.storage.init(config);
|
2017-04-10 15:00:41 -05:00
|
|
|
Search.configureStorage(this.storage);
|
|
|
|
packages.map(function(item) {
|
|
|
|
Search.add(item);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
test('search query item', () => {
|
2017-04-19 14:15:28 -05:00
|
|
|
let result = Search.query('t');
|
2017-04-10 15:00:41 -05:00
|
|
|
assert(result.length === 3);
|
2017-04-20 03:50:48 -05:00
|
|
|
});
|
2017-04-10 15:00:41 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
test('search remove item', () => {
|
2017-04-19 14:15:28 -05:00
|
|
|
let item = {
|
2017-04-10 15:00:41 -05:00
|
|
|
name: 'test6',
|
|
|
|
description: 'description',
|
|
|
|
_npmUser: {
|
|
|
|
name: 'test_user',
|
2017-04-19 14:15:28 -05:00
|
|
|
},
|
2017-04-10 15:00:41 -05:00
|
|
|
};
|
|
|
|
Search.add(item);
|
2017-04-23 13:02:26 -05:00
|
|
|
let result = Search.query('test6');
|
2017-04-10 15:00:41 -05:00
|
|
|
assert(result.length === 1);
|
|
|
|
Search.remove(item.name);
|
2017-04-23 13:02:26 -05:00
|
|
|
result = Search.query('test6');
|
2017-04-10 15:00:41 -05:00
|
|
|
assert(result.length === 0);
|
2017-04-20 03:50:48 -05:00
|
|
|
});
|
|
|
|
});
|