Move url route into general asset search

This commit is contained in:
David Erwin
2016-11-05 14:44:42 -04:00
parent 2c217c240a
commit c1359a9af9
3 changed files with 18 additions and 19 deletions
+2 -2
View File
@@ -38,9 +38,9 @@ const AssetSchema = new Schema({
/**
* Search for assets. Currently only returns all.
*/
AssetSchema.statics.search = function() {
AssetSchema.statics.search = function(query) {
return Asset.find({});
return Asset.find(query);
};
+8 -12
View File
@@ -2,10 +2,16 @@ const express = require('express');
const router = express.Router();
const Asset = require('../../../models/asset');
// Get many assets
// Search assets.
router.get('/', (req, res) => {
Asset.search(req.params.id)
let query = {};
if (typeof req.query.url !== 'undefined') {
query.url = req.query.url;
}
Asset.search(query)
.then((asset) => {
res.json(asset);
});
@@ -22,16 +28,6 @@ router.get('/:id', (req, res) => {
});
// Get an asset by url
router.get('/url/:url', (req, res) => {
Asset.findByUrl(req.params.url)
.then((asset) => {
res.json(asset);
});
});
// Upsert an asset and return the affected document.
router.put('/', (req, res) => {
+8 -5
View File
@@ -11,7 +11,7 @@ should; // nullop to satisfy linting
chai.use(chaiHttp);
var fixture = {
'url': 'simple',
'url': 'http://hhgg.com/total-perspective-vortex',
'type': 'article',
'headline': 'The Total Perspective Vortex',
'summary': 'You are an insignificant dot on an insignificant dot.',
@@ -81,7 +81,7 @@ describe('Asset', () => {
// Load the asset to make sure it's really there.
chai.request(server)
.get('/api/v1/asset/url/' + fixture.url)
.get('/api/v1/asset?url=' + fixture.url)
.end((err, res) => {
if (err) {
@@ -89,12 +89,15 @@ describe('Asset', () => {
}
res.should.have.status(200);
res.body.should.be.a('object');
res.body.should.have.property('id');
res.body.should.be.an('array');
let asset = res.body[0];
expect(asset).to.have.property('id');
// Ensure the asset has the same id as above.
// This tests the single url per Id concept.
expect(assetId).to.equal(res.body.id);
expect(assetId).to.equal(asset.id);
done();