amalgamatic
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -1,6 +0,11 @@ | ||
# 2014-09-16 | ||
7 commits against 1 issues, over 8 hours [`e2d158a`](https://github.com/ucsf-ckm/amalgamatic/commit/e2d158a)⎆[`e966def`](https://github.com/ucsf-ckm/amalgamatic/commit/e966def) | ||
## [**2.0.0**](https://github.com/ucsf-ckm/amalgamatic/issues?milestone=2&state=closed) | ||
- [**#12**](https://github.com/ucsf-ckm/amalgamatic/issues/12) Move libguides collector to its own npm module | ||
- [**#11**](https://github.com/ucsf-ckm/amalgamatic/issues/11) Move millennium collector to its own npm module | ||
- [**#8**](https://github.com/ucsf-ckm/amalgamatic/issues/8) add() should load collectors from npm modules | ||
- [**#6**](https://github.com/ucsf-ckm/amalgamatic/issues/6) Add libguides connector | ||
- [**#2**](https://github.com/ucsf-ckm/amalgamatic/issues/2) Add configurability | ||
## [**1.1.0**](https://github.com/ucsf-ckm/amalgamatic/issues?milestone=1&state=closed) | ||
- [**#1**](https://github.com/ucsf-ckm/amalgamatic/issues/1) Millennium should be a default collection | ||
39
index.js
@@ -1,1 +0,38 @@ | ||
exports.search = require('./lib/search'); | ||
var async = require('async'); | ||
var collections = {}; | ||
exports.search = function (req, res) { | ||
'use strict'; | ||
var requestedCollections; | ||
if (! req.query.c || ! req.query.c instanceof Array) { | ||
requestedCollections = Object.keys(collections); | ||
} else { | ||
requestedCollections = req.query.c; | ||
} | ||
var results = {}; | ||
var iterator = function (c, done) { | ||
if (c in collections) { | ||
collections[c].search(req.query.q, function (value) { | ||
results[c] = {data: value.data}; | ||
done(); | ||
}); | ||
} else { | ||
results[c] = {error: 'Collection "' + c + '" does not exist'}; | ||
done(); | ||
} | ||
}; | ||
var callback = function () { | ||
res.json(results); | ||
}; | ||
async.each(requestedCollections, iterator, callback); | ||
}; | ||
exports.add = function (name, collector) { | ||
collections[name] = collector; | ||
}; |
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"dependencies": { | ||
@@ -21,4 +21,5 @@ "async": "^0.9.0", | ||
"devDependencies": { | ||
"amalgamatic-sfx": "^1.0.0", | ||
"jshint": "^2.5.5", | ||
"lab": "^4.3.0", | ||
"lab": "^4.4.4", | ||
"nock": "^0.47.0", | ||
@@ -25,0 +26,0 @@ "precommit-hook": "^1.0.7" |
/*jshint expr: true*/ | ||
var amalgamatic = require('../index.js'); | ||
var sfx = require('amalgamatic-sfx'); | ||
amalgamatic.add('sfx', sfx); | ||
var Lab = require('lab'); | ||
@@ -12,4 +15,27 @@ var lab = exports.lab = Lab.script(); | ||
describe('amalgamatic', function () { | ||
var nock = require('nock'); | ||
var EventEmitter = require('events').EventEmitter; | ||
var emitter = new EventEmitter(); | ||
describe('exports', function () { | ||
var res = { | ||
json: function(value) { | ||
emitter.emit('end', value); | ||
} | ||
}; | ||
var searchHelper = function (q, c, callback) { | ||
var req = { | ||
query: { | ||
q: q, | ||
c: c | ||
} | ||
}; | ||
emitter.once('end', callback); | ||
amalgamatic.search(req, res); | ||
}; | ||
it('should have a search property', function (done) { | ||
@@ -19,2 +45,42 @@ expect(typeof amalgamatic.search).to.equal('function'); | ||
}); | ||
it('returns only specified collection', function (done) { | ||
nock('http://ucelinks.cdlib.org:8888') | ||
.get('/sfx_ucsf/az?param_textSearchType_value=startsWith¶m_pattern_value=medicine') | ||
.reply('200', '<a class="Results" href="#">Medicine</a><a class="Results" href="#">Medicine</a>'); | ||
searchHelper('medicine', ['sfx'], function (results) { | ||
expect(results.sfx.data.length > 0).to.be.true; | ||
expect(results.sfx.error).to.be.undefined; | ||
done(); | ||
}); | ||
}); | ||
it('returns an error if an invalid collection is specified', function (done) { | ||
searchHelper('medicine', ['fhqwhgads'], function (results) { | ||
expect(results.fhqwhgads.data).to.be.undefined; | ||
expect(results.fhqwhgads.error).to.equal('Collection "fhqwhgads" does not exist'); | ||
done(); | ||
}); | ||
}); | ||
it('returns multiple collections if specified', function (done) { | ||
nock('http://ucelinks.cdlib.org:8888') | ||
.get('/sfx_ucsf/az?param_textSearchType_value=startsWith¶m_pattern_value=medicine') | ||
.reply('200', '<a class="Results" href="#">Medicine</a><a class="Results" href="#">Medicine</a>'); | ||
searchHelper('medicine', ['sfx', 'fhqwhgads'], function (results) { | ||
expect(results.sfx.data).to.be.ok; | ||
expect(results.fhqwhgads.error).to.be.ok; | ||
done(); | ||
}); | ||
}); | ||
it('returns all collections if no collection specified', function (done) { | ||
searchHelper('medicine', null, function (results) { | ||
expect(results.sfx.data).to.be.ok; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
1
6398
5
9
95