1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/test/unit/search.js

66 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-04-19 21:15:28 +02:00
'use strict';
let assert = require('assert');
let Search = require('../../lib/search');
let Storage = require('../../lib/storage');
let config_hash = require('./partials/config');
let Config = require('../../lib/config');
2017-04-10 22:00:41 +02:00
require('../../lib/logger').setup([]);
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
describe('search', function() {
before(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);
Search.configureStorage(this.storage);
packages.map(function(item) {
Search.add(item);
});
});
it('search query item', function() {
2017-04-19 21:15:28 +02:00
let result = Search.query('t');
2017-04-10 22:00:41 +02:00
assert(result.length === 3);
});
2017-04-10 22:00:41 +02:00
it('search remove item', function() {
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');
2017-04-10 22:00:41 +02:00
assert(result.length === 1);
Search.remove(item.name);
result = Search.query('test6');
2017-04-10 22:00:41 +02:00
assert(result.length === 0);
});
});