Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
Wrapper to ensure {Crawls: []}
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Cash committed Oct 26, 2019
1 parent bff9be6 commit 2a41a2d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
6 changes: 5 additions & 1 deletion helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ exports.url_refer = (url)=>{
return url+="?utm_source=hackerqueue"
}
return url
};
};

exports.wrap = (arr)=>{
return {Crawls: arr}
}
4 changes: 2 additions & 2 deletions routes/hackernews.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function parse(html){
exports.htop = function(req,res){
request('https://news.ycombinator.com', function(error, response, html){
if(!error && response.statusCode === 200){
res.send({Crawls: parse(html, "news.ycombinator.com")});
res.send(helpers.wrap(parse(html, "news.ycombinator.com")));
}
});

Expand All @@ -48,7 +48,7 @@ exports.htop = function(req,res){
exports.hnew = function(req,res){
request('https://news.ycombinator.com/newest', function(error, response, html){
if(!error && response.statusCode === 200){
res.send({Crawls: parse(html, "news.ycombinator.com/newest")});
res.send(helpers.wrap(parse(html, "news.ycombinator.com/newest")));
}
});

Expand Down
6 changes: 3 additions & 3 deletions routes/lobsters.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ const parseLobsterResponse = function(html) {
exports.ltop = function(req, res){
request('https://lobste.rs', function(error, response, html){
if(!error && response.statusCode === 200){
let metadataArray = parseLobsterResponse(html);
res.send({Crawls: metadataArray});
const metadataArray = parseLobsterResponse(html);
res.send(helpers.wrap(metadataArray));
}
});
};
Expand All @@ -100,7 +100,7 @@ exports.lnew = function(req, res){
request('https://lobste.rs/recent', function(error, response, html){
if(!error && response.statusCode === 200){
const metadataArray = parseLobsterResponse(html);
res.send({Crawls: metadataArray});
res.send(helpers.wrap(metadataArray));
}
});
};
4 changes: 2 additions & 2 deletions routes/reddit.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function parse(html, source){
exports.rtop = function(req,res){
request('http://www.reddit.com/r/programming', function(error, response, html){
if(!error && response.statusCode === 200){
res.send({Crawls: parse(html, "reddit.com/r/programming")});
res.send(helpers.wrap(parse(html, "reddit.com/r/programming")));
}
});
};
Expand All @@ -63,7 +63,7 @@ exports.rtop = function(req,res){
exports.rnew = function(req,res){
request('http://www.reddit.com/r/programming/new/', function(error, response, html){
if(!error && response.statusCode === 200){
res.send({Crawls: parse(html, "reddit.com/r/programming/new")});
res.send(helpers.wrap(parse(html, "reddit.com/r/programming/new")));
}
});
};
11 changes: 11 additions & 0 deletions test/metadata_wrapper.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const assert = require('assert');
const helpers = require('../helpers');

describe('MetaData Array Modification', ()=>{
describe("Wrapper", ()=>{
it("Shuld return a JSON object instead of an Array", function(){
const res = helpers.wrap([{url: "localhost:3000"}])
assert.equal(res.Crawls.length, 1)
});
});
})

0 comments on commit 2a41a2d

Please sign in to comment.