Skip to content

Commit

Permalink
Merge pull request rlidwka#154 from verdaccio/unit_testing
Browse files Browse the repository at this point in the history
Unit testing for Search.js
  • Loading branch information
juanpicado authored Apr 13, 2017
2 parents ee99d1f + ea1ed41 commit 32d7e8d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 12 deletions.
13 changes: 13 additions & 0 deletions test/unit/partials/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var config = {
storage: __dirname + '/test-storage',
packages: {
'*': {
allow_access: '$all',
},
},
logs: [
{type: 'stdout', format: 'pretty', level: 'fatal'}
],
}

module.exports = config;
66 changes: 66 additions & 0 deletions test/unit/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
var assert = require('assert');
var Search = require('../../lib/search');
var Storage = require('../../lib/storage');
var config_hash = require('./partials/config');
var Config = require('../../lib/config');

require('../../lib/logger').setup([]);

var 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', function() {

before(function() {
var config = Config(config_hash);
this.storage = new Storage(config);
Search.configureStorage(this.storage);
packages.map(function(item) {
Search.add(item);
});
});

it('search query item', function() {
var result = Search.query('t');
assert(result.length === 3);
})

it('search remove item', function() {
var item = {
name: 'test6',
description: 'description',
_npmUser: {
name: 'test_user',
}
};
Search.add(item);
var result = Search.query('test6');
assert(result.length === 1);
Search.remove(item.name);
var result = Search.query('test6');
assert(result.length === 0);
})

})

13 changes: 1 addition & 12 deletions test/unit/toplevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@ var express = require('express')
var request = require('request')
var rimraf = require('rimraf')
var verdaccio = require('../../')

var config = {
storage: __dirname + '/test-storage',
packages: {
'*': {
allow_access: '$all',
},
},
logs: [
{type: 'stdout', format: 'pretty', level: 'fatal'}
],
}
var config = require('./partials/config');

describe('toplevel', function() {
var port
Expand Down

0 comments on commit 32d7e8d

Please sign in to comment.