Updated Mocha tests
This commit is contained in:
parent
6b3e8ae3f1
commit
5d60813cc0
@ -10,6 +10,8 @@ const htmlTidy = /<(\/*?)(?!(em|p|br\s*\/|strong|h1|h2|h3))\w+?.+?>/gim;
|
||||
function reduceEstDirections(body = '') {
|
||||
if (body === '') return {};
|
||||
|
||||
console.log(body);
|
||||
|
||||
const jBody = JSON.parse(body);
|
||||
const obj = {};
|
||||
const { ResultSet } = jBody;
|
||||
|
@ -330,12 +330,12 @@ const requestData = {
|
||||
}
|
||||
};
|
||||
|
||||
const goodOutput = { 'totalTime': '65.0',
|
||||
'totalTimeWithTraffic': '70.0',
|
||||
const goodOutput = { 'totalTime': 65,
|
||||
'totalTimeWithTraffic': 70,
|
||||
'readable': '1 hour, 10 minutes',
|
||||
'timePercentage': 10.5,
|
||||
'traffic': 'no traffic',
|
||||
'class': 'trafficNone' };
|
||||
'className': 'trafficNone' };
|
||||
|
||||
describe('Directions', () => {
|
||||
it('should gracefully handle no data', done => {
|
||||
@ -344,7 +344,7 @@ describe('Directions', () => {
|
||||
});
|
||||
|
||||
it('Should process data correctly', done => {
|
||||
expect(reduceEstDirections(requestData)).to.eql(goodOutput);
|
||||
expect(reduceEstDirections(JSON.stringify(requestData))).to.eql(goodOutput);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
File diff suppressed because one or more lines are too long
@ -492,65 +492,109 @@ const fullFS = {
|
||||
}
|
||||
};
|
||||
|
||||
describe('Explore', () => {
|
||||
it('should gracefully handle no data', done => {
|
||||
expect(reduceExplore()).to.eql({});
|
||||
done();
|
||||
const goodMergeResult = {
|
||||
'latitude': 56.39449115920086,
|
||||
'longitude': -5.1161516920810755,
|
||||
'name': 'Cruachan Power Station',
|
||||
'category': 'Building',
|
||||
'icon': 'https://ss3.4sqi.net/img/categories_v2/building/default_64.png',
|
||||
'id': '4c233b549a67a5937ea7dd87',
|
||||
'provider': 'foursquare',
|
||||
'address': 'A85, Dalmally, PA33 1AN, United Kingdom',
|
||||
'city': 'Dalmally',
|
||||
'state': '',
|
||||
'postcode': 'PA33 1AN',
|
||||
'twitter': '',
|
||||
'facebook': '',
|
||||
'url': 'http://www.visitcruachan.co.uk',
|
||||
'images': ['https://igx.4sqi.net/img/general/640x640/16198007__KficeTL_D2tiqT7Zgu3wJyiL0485yVS_uNYAtCHOxw.jpg',
|
||||
'https://igx.4sqi.net/img/general/640x640/16198007_gXoDHf06UwW-n-hUe8ul5udJut2DDZ7GocGN0Akn6IA.jpg',
|
||||
'https://igx.4sqi.net/img/general/640x480/cWA5MDOAyYCEqszteU7y4Fgq3W9ngKrNaXNIF3VraEc.jpg',
|
||||
'https://igx.4sqi.net/img/general/640x858/4442790_8SNrTl-wGnc9c6Ds7bHdcZeqbT9T-ScMw36KErzLDhU.jpg',
|
||||
'https://igx.4sqi.net/img/general/640x853/4353161_Rr_HCB-pEhemJxkBAmH5wWN68rju4MhbtEahLFa8trk.jpg'],
|
||||
'tips': ['Bring your O2 or Vodafone phone so you can actually get a signal to check in!', 'a good exscuse for a check in!'],
|
||||
'yelp': {
|
||||
'url': 'https://www.yelp.com/biz/cruachan-power-station-visitor-centre-dalmally?adjust_creative=s8FdwjzKWCpdbkUzShvAgg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=s8FdwjzKWCpdbkUzShvAgg',
|
||||
'rating': 4.5,
|
||||
'reviewCount': 2,
|
||||
'viewIntent': 'https://m.yelp.com/biz/cruachan-power-station-visitor-centre-dalmally?adjust_creative=s8FdwjzKWCpdbkUzShvAgg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=s8FdwjzKWCpdbkUzShvAgg'
|
||||
}
|
||||
};
|
||||
|
||||
const goodExplore = { 'latitude': 56.39449115920086, 'longitude': -5.1161516920810755, 'name':'Cruachan Power Station', 'category':'Building', 'icon':'https://ss3.4sqi.net/img/categories_v2/building/default_64.png', 'id':'4c233b549a67a5937ea7dd87', 'provider':'foursquare', 'address':'A85, Dalmally, PA33 1AN, United Kingdom', 'city':'Dalmally', 'state':'', 'postcode':'PA33 1AN', 'twitter':'', 'facebook':'', 'url':'http://www.visitcruachan.co.uk' };
|
||||
|
||||
const goodFS = {
|
||||
|
||||
'images': ['https://igx.4sqi.net/img/general/640x640/16198007__KficeTL_D2tiqT7Zgu3wJyiL0485yVS_uNYAtCHOxw.jpg',
|
||||
'https://igx.4sqi.net/img/general/640x640/16198007_gXoDHf06UwW-n-hUe8ul5udJut2DDZ7GocGN0Akn6IA.jpg',
|
||||
'https://igx.4sqi.net/img/general/640x480/cWA5MDOAyYCEqszteU7y4Fgq3W9ngKrNaXNIF3VraEc.jpg',
|
||||
'https://igx.4sqi.net/img/general/640x858/4442790_8SNrTl-wGnc9c6Ds7bHdcZeqbT9T-ScMw36KErzLDhU.jpg',
|
||||
'https://igx.4sqi.net/img/general/640x853/4353161_Rr_HCB-pEhemJxkBAmH5wWN68rju4MhbtEahLFa8trk.jpg'],
|
||||
'tips': ['Bring your O2 or Vodafone phone so you can actually get a signal to check in!', 'a good exscuse for a check in!']
|
||||
};
|
||||
|
||||
describe('Right By Me', () => {
|
||||
describe('Explore', () => {
|
||||
it('should gracefully handle no data', done => {
|
||||
expect(reduceExplore()).to.eql({});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should process data correctly', done => {
|
||||
expect(reduceExplore(exploreFS)).to.eql(goodExplore);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should process data correctly', done => {
|
||||
expect(reduceExplore(exploreFS)).to.eql({ 'name':'Cruachan Power Station', 'category':'Building', 'icon':'https://ss3.4sqi.net/img/categories_v2/building/default_64.png', 'id':'4c233b549a67a5937ea7dd87', 'provider':'foursquare', 'address':'A85, Dalmally, PA33 1AN, United Kingdom', 'city':'Dalmally', 'state':'', 'postcode':'PA33 1AN', 'twitter':'', 'facebook':'', 'url':'http://www.visitcruachan.co.uk' });
|
||||
done();
|
||||
describe('Yelp', () => {
|
||||
it('should gracefully handle no data', done => {
|
||||
expect(reduceYelp()).to.eql({});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should process data correctly', done => {
|
||||
expect(reduceYelp(YelpData)).to.eql({ 'url':'https://www.yelp.com/biz/cruachan-power-station-visitor-centre-dalmally?adjust_creative=s8FdwjzKWCpdbkUzShvAgg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=s8FdwjzKWCpdbkUzShvAgg', 'rating':4.5, 'reviewCount':2, 'viewIntent':'https://m.yelp.com/biz/cruachan-power-station-visitor-centre-dalmally?adjust_creative=s8FdwjzKWCpdbkUzShvAgg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=s8FdwjzKWCpdbkUzShvAgg' });
|
||||
done();
|
||||
});
|
||||
|
||||
it('should handle Missing Url', done => {
|
||||
const brokenYelp = Object.assign({}, YelpData);
|
||||
|
||||
delete brokenYelp.url;
|
||||
|
||||
expect(reduceYelp(brokenYelp)).to.eql({ 'url':'', 'rating':4.5, 'reviewCount':2, 'viewIntent':'' });
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Full FS', () => {
|
||||
it('should gracefully handle no data', done => {
|
||||
expect(reduceFullFS()).to.eql({});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should process data correctly', done => {
|
||||
expect(reduceFullFS(fullFS)).to.eql(goodFS);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Merging', () => {
|
||||
it('should gracefully handle no data', done => {
|
||||
const m = Object.assign(reduceExplore(), reduceFullFS());
|
||||
|
||||
expect(m).to.eql({});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should Merge Cruachan correctly', done => {
|
||||
const m = Object.assign(reduceExplore(exploreFS), reduceFullFS(fullFS));
|
||||
const yelp = reduceYelp(YelpData);
|
||||
m.yelp = yelp;
|
||||
expect(m).to.eql(goodMergeResult);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Yelp', () => {
|
||||
it('should gracefully handle no data', done => {
|
||||
expect(reduceYelp()).to.eql({});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should process data correctly', done => {
|
||||
expect(reduceYelp(YelpData)).to.eql({ 'url':'https://www.yelp.com/biz/cruachan-power-station-visitor-centre-dalmally?adjust_creative=s8FdwjzKWCpdbkUzShvAgg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=s8FdwjzKWCpdbkUzShvAgg', 'rating':4.5, 'reviewCount':2, 'viewIntent':'https://m.yelp.com/biz/cruachan-power-station-visitor-centre-dalmally?adjust_creative=s8FdwjzKWCpdbkUzShvAgg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=s8FdwjzKWCpdbkUzShvAgg' });
|
||||
done();
|
||||
});
|
||||
|
||||
it('should handle Missing Url', done => {
|
||||
const brokenYelp = Object.assign({}, YelpData);
|
||||
|
||||
delete brokenYelp.url;
|
||||
|
||||
expect(reduceYelp(brokenYelp)).to.eql({ 'url':'', 'rating':4.5, 'reviewCount':2, 'viewIntent':'' });
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Full FS', () => {
|
||||
it('should gracefully handle no data', done => {
|
||||
expect(reduceFullFS()).to.eql({});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should process data correctly', done => {
|
||||
expect(reduceFullFS(fullFS)).to.eql({ 'images':['https://igx.4sqi.net/img/general//16198007__KficeTL_D2tiqT7Zgu3wJyiL0485yVS_uNYAtCHOxw.jpg', 'https://igx.4sqi.net/img/general//16198007_gXoDHf06UwW-n-hUe8ul5udJut2DDZ7GocGN0Akn6IA.jpg', 'https://igx.4sqi.net/img/general//cWA5MDOAyYCEqszteU7y4Fgq3W9ngKrNaXNIF3VraEc.jpg', 'https://igx.4sqi.net/img/general//4442790_8SNrTl-wGnc9c6Ds7bHdcZeqbT9T-ScMw36KErzLDhU.jpg', 'https://igx.4sqi.net/img/general//4353161_Rr_HCB-pEhemJxkBAmH5wWN68rju4MhbtEahLFa8trk.jpg'], 'tips':['Bring your O2 or Vodafone phone so you can actually get a signal to check in!', 'a good exscuse for a check in!'] });
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Merging', () => {
|
||||
it('should gracefully handle no data', done => {
|
||||
const m = Object.assign(reduceExplore(), reduceFullFS());
|
||||
|
||||
expect(m).to.eql({});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should Merge Cruachan correctly', done => {
|
||||
const m = Object.assign(reduceExplore(exploreFS), reduceFullFS(fullFS));
|
||||
const yelp = reduceYelp(YelpData);
|
||||
m.yelp = yelp;
|
||||
expect(m).to.eql({ 'name':'Cruachan Power Station', 'category':'Building', 'icon':'https://ss3.4sqi.net/img/categories_v2/building/default_64.png', 'id':'4c233b549a67a5937ea7dd87', 'provider':'foursquare', 'address':'A85, Dalmally, PA33 1AN, United Kingdom', 'city':'Dalmally', 'state':'', 'postcode':'PA33 1AN', 'twitter':'', 'facebook':'', 'url':'http://www.visitcruachan.co.uk', 'images':['https://igx.4sqi.net/img/general//16198007__KficeTL_D2tiqT7Zgu3wJyiL0485yVS_uNYAtCHOxw.jpg', 'https://igx.4sqi.net/img/general//16198007_gXoDHf06UwW-n-hUe8ul5udJut2DDZ7GocGN0Akn6IA.jpg', 'https://igx.4sqi.net/img/general//cWA5MDOAyYCEqszteU7y4Fgq3W9ngKrNaXNIF3VraEc.jpg', 'https://igx.4sqi.net/img/general//4442790_8SNrTl-wGnc9c6Ds7bHdcZeqbT9T-ScMw36KErzLDhU.jpg', 'https://igx.4sqi.net/img/general//4353161_Rr_HCB-pEhemJxkBAmH5wWN68rju4MhbtEahLFa8trk.jpg'], 'tips':['Bring your O2 or Vodafone phone so you can actually get a signal to check in!', 'a good exscuse for a check in!'], 'yelp':{ 'url':'https://www.yelp.com/biz/cruachan-power-station-visitor-centre-dalmally?adjust_creative=s8FdwjzKWCpdbkUzShvAgg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=s8FdwjzKWCpdbkUzShvAgg', 'rating':4.5, 'reviewCount':2, 'viewIntent':'https://m.yelp.com/biz/cruachan-power-station-visitor-centre-dalmally?adjust_creative=s8FdwjzKWCpdbkUzShvAgg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=s8FdwjzKWCpdbkUzShvAgg' } });
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -1526,6 +1526,8 @@ describe('Weather', () => {
|
||||
});
|
||||
|
||||
it('Should process data correctly', done => {
|
||||
|
||||
console.log(JSON.stringify(reduceWeather(requestData)));
|
||||
expect(reduceWeather(requestData)).to.eql(goodOutput);
|
||||
done();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user