const { reduceExplore, reduceYelp, reduceFullFS } = require('../server/reducers/rightbyme'); const expect = require('expect.js'); const exploreFS = { 'id': '4c233b549a67a5937ea7dd87', 'name': 'Cruachan Power Station', 'contact': { 'phone': '+441866822618', 'formattedPhone': '+44 1866 822618' }, 'location': { 'address': 'A85', 'lat': 56.39449115920086, 'lng': -5.1161516920810755, 'labeledLatLngs': [ { 'label': 'display', 'lat': 56.39449115920086, 'lng': -5.1161516920810755 } ], 'distance': 30, 'postalCode': 'PA33 1AN', 'cc': 'GB', 'city': 'Dalmally', 'country': 'United Kingdom', 'formattedAddress': [ 'A85', 'Dalmally', 'PA33 1AN', 'United Kingdom' ] }, 'categories': [ { 'id': '4bf58dd8d48988d130941735', 'name': 'Building', 'pluralName': 'Buildings', 'shortName': 'Building', 'icon': { 'prefix': 'https://ss3.4sqi.net/img/categories_v2/building/default_', 'suffix': '.png' }, 'primary': true } ], 'verified': false, 'stats': { 'tipCount': 2, 'usersCount': 98, 'checkinsCount': 100 }, 'url': 'http://www.visitcruachan.co.uk', 'venueRatingBlacklisted': true, 'beenHere': { 'count': 0, 'marked': false, 'lastCheckinExpiredAt': 0 }, 'photos': { 'count': 0, 'groups': [] }, 'hereNow': { 'count': 0, 'summary': 'Nobody here', 'groups': [] } }; const YelpData = { 'id': 'cruachan-power-station-visitor-centre-dalmally', 'name': 'Cruachan Power Station Visitor Centre', 'image_url': 'https://s3-media2.fl.yelpcdn.com/bphoto/eRvbe7h4JBGQB5g1P0iWFg/o.jpg', 'is_closed': false, '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', 'review_count': 2, 'categories': [ { 'alias': 'visitorcenters', 'title': 'Visitor Centers' } ], 'rating': 4.5, 'coordinates': { 'latitude': 56.394515, 'longitude': -5.116196 }, 'transactions': [], 'location': { 'address1': 'Cruachan Power Station', 'address2': null, 'address3': null, 'city': 'Dalmally', 'zip_code': 'PA33 1AN', 'country': 'GB', 'state': 'AGB', 'display_address': [ 'Cruachan Power Station', 'Dalmally PA33 1AN', 'United Kingdom' ] }, 'phone': '+441866822618', 'display_phone': '+44 1866 822618', 'distance': 2.360238088184 }; const fullFS = { 'id': '4c233b549a67a5937ea7dd87', 'name': 'Cruachan Power Station', 'contact': { 'phone': '+441866822618', 'formattedPhone': '+44 1866 822618' }, 'location': { 'address': 'A85', 'lat': 56.39449115920086, 'lng': -5.1161516920810755, 'labeledLatLngs': [ { 'label': 'display', 'lat': 56.39449115920086, 'lng': -5.1161516920810755 } ], 'postalCode': 'PA33 1AN', 'cc': 'GB', 'city': 'Dalmally', 'country': 'United Kingdom', 'formattedAddress': [ 'A85', 'Dalmally', 'PA33 1AN', 'United Kingdom' ] }, 'canonicalUrl': 'https://foursquare.com/v/cruachan-power-station/4c233b549a67a5937ea7dd87', 'categories': [ { 'id': '4bf58dd8d48988d130941735', 'name': 'Building', 'pluralName': 'Buildings', 'shortName': 'Building', 'icon': { 'prefix': 'https://ss3.4sqi.net/img/categories_v2/building/default_', 'suffix': '.png' }, 'primary': true }, { 'id': '4bf58dd8d48988d165941735', 'name': 'Scenic Lookout', 'pluralName': 'Scenic Lookouts', 'shortName': 'Scenic Lookout', 'icon': { 'prefix': 'https://ss3.4sqi.net/img/categories_v2/parks_outdoors/sceniclookout_', 'suffix': '.png' } } ], 'verified': false, 'stats': { 'tipCount': 2, 'usersCount': 146, 'checkinsCount': 100, 'visitsCount': 150 }, 'url': 'http://www.visitcruachan.co.uk', 'likes': { 'count': 3, 'groups': [ { 'type': 'others', 'count': 3, 'items': [ { 'id': '148882502', 'firstName': 'James', 'lastName': 'Braid', 'gender': 'none', 'photo': { 'prefix': 'https://igx.4sqi.net/img/user/', 'suffix': '/blank_boy.png', 'default': true } }, { 'id': '21137780', 'firstName': 'Simon', 'lastName': 'Gregory', 'gender': 'male', 'photo': { 'prefix': 'https://igx.4sqi.net/img/user/', 'suffix': '/NZ5Z5VJMRRNPKIPL.jpg' } } ] } ], 'summary': '3 Likes' }, 'dislike': false, 'ok': false, 'venueRatingBlacklisted': true, 'beenHere': { 'count': 0, 'unconfirmedCount': 0, 'marked': false, 'lastCheckinExpiredAt': 0 }, 'specials': { 'count': 0, 'items': [] }, 'photos': { 'count': 5, 'groups': [ { 'type': 'venue', 'name': 'Venue photos', 'count': 5, 'items': [ { 'id': '51878588498e053c231b5333', 'createdAt': 1367836040, 'source': { 'name': 'Instagram', 'url': 'http://instagram.com' }, 'prefix': 'https://igx.4sqi.net/img/general/', 'suffix': '/16198007__KficeTL_D2tiqT7Zgu3wJyiL0485yVS_uNYAtCHOxw.jpg', 'width': 612, 'height': 612, 'user': { 'id': '16198007', 'firstName': 'houdi', 'gender': 'male', 'photo': { 'prefix': 'https://igx.4sqi.net/img/user/', 'suffix': '/C1OQYP3FHOP2YJYM.jpg' } }, 'visibility': 'public' }, { 'id': '5187853e498ee4fb7757a79e', 'createdAt': 1367835966, 'source': { 'name': 'Instagram', 'url': 'http://instagram.com' }, 'prefix': 'https://igx.4sqi.net/img/general/', 'suffix': '/16198007_gXoDHf06UwW-n-hUe8ul5udJut2DDZ7GocGN0Akn6IA.jpg', 'width': 612, 'height': 612, 'user': { 'id': '16198007', 'firstName': 'houdi', 'gender': 'male', 'photo': { 'prefix': 'https://igx.4sqi.net/img/user/', 'suffix': '/C1OQYP3FHOP2YJYM.jpg' } }, 'visibility': 'public' }, { 'id': '4fd9da1ee4b0ea76a6c80417', 'createdAt': 1339677214, 'source': { 'name': 'Foursquare for Android', 'url': 'https://foursquare.com/download/#/android' }, 'prefix': 'https://igx.4sqi.net/img/general/', 'suffix': '/cWA5MDOAyYCEqszteU7y4Fgq3W9ngKrNaXNIF3VraEc.jpg', 'width': 640, 'height': 480, 'user': { 'id': '2597712', 'firstName': 'Nia', 'lastName': 'Wearn', 'gender': 'female', 'photo': { 'prefix': 'https://igx.4sqi.net/img/user/', 'suffix': '/QWON2DY3SGFP0JIN.jpg' } }, 'visibility': 'public' }, { 'id': '50ceeb05e4b01c69f47dd479', 'createdAt': 1355737861, 'source': { 'name': 'Foursquare for iOS', 'url': 'https://foursquare.com/download/#/iphone' }, 'prefix': 'https://igx.4sqi.net/img/general/', 'suffix': '/4442790_8SNrTl-wGnc9c6Ds7bHdcZeqbT9T-ScMw36KErzLDhU.jpg', 'width': 537, 'height': 720, 'user': { 'id': '4442790', 'firstName': 'Rachel', 'lastName': 'Brown', 'gender': 'female', 'photo': { 'prefix': 'https://igx.4sqi.net/img/user/', 'suffix': '/40RRMDM10221RS0R.jpg' } }, 'visibility': 'public' }, { 'id': '5374b0f9498e9e41f159e8fe', 'createdAt': 1400156409, 'source': { 'name': 'Foursquare for iOS', 'url': 'https://foursquare.com/download/#/iphone' }, 'prefix': 'https://igx.4sqi.net/img/general/', 'suffix': '/4353161_Rr_HCB-pEhemJxkBAmH5wWN68rju4MhbtEahLFa8trk.jpg', 'width': 720, 'height': 960, 'user': { 'id': '4353161', 'firstName': 'sunita', 'lastName': 'panich', 'gender': 'none', 'photo': { 'prefix': 'https://igx.4sqi.net/img/user/', 'suffix': '/I3HAQMV2YTOMNU50.jpg' } }, 'visibility': 'public' } ] } ] }, 'reasons': { 'count': 0, 'items': [] }, 'hereNow': { 'count': 0, 'summary': 'Nobody here', 'groups': [] }, 'createdAt': 1277377364, 'tips': { 'count': 2, 'groups': [ { 'type': 'others', 'name': 'All tips', 'count': 2, 'items': [ { 'id': '4d93304df7e8dcb3e594cb12', 'createdAt': 1301491789, 'text': 'Bring your O2 or Vodafone phone so you can actually get a signal to check in!', 'type': 'user', 'canonicalUrl': 'https://foursquare.com/item/4d93304df7e8dcb3e594cb12', 'likes': { 'count': 0, 'groups': [] }, 'logView': true, 'agreeCount': 0, 'disagreeCount': 0, 'todo': { 'count': 0 }, 'user': { 'id': '530470', 'firstName': 'Rob', 'lastName': 'Fisher', 'gender': 'male', 'photo': { 'prefix': 'https://igx.4sqi.net/img/user/', 'suffix': '/XAZKL04TO3CU0BCG.jpg' } } }, { 'id': '4d650ad689238cfa81459436', 'createdAt': 1298467542, 'text': 'a good exscuse for a check in!', 'type': 'user', 'canonicalUrl': 'https://foursquare.com/item/4d650ad689238cfa81459436', 'likes': { 'count': 0, 'groups': [] }, 'logView': true, 'agreeCount': 0, 'disagreeCount': 0, 'todo': { 'count': 0 }, 'user': { 'id': '4808723', 'firstName': 'Anna', 'lastName': 'Hastings', 'gender': 'female', 'photo': { 'prefix': 'https://igx.4sqi.net/img/user/', 'suffix': '/LM5A3CIS2TT1UHXX.jpg' } } } ] } ] }, 'shortUrl': 'http://4sq.com/b9RihM', 'timeZone': 'Europe/London', 'listed': { 'count': 1, 'groups': [ { 'type': 'others', 'name': 'Lists from other people', 'count': 1, 'items': [ { 'id': '51ffd2de498e3955660fd8b7', 'name': 'Holiday', 'description': '', 'type': 'others', 'user': { 'id': '48298321', 'firstName': 'Hans', 'lastName': 'Peeters', 'gender': 'male', 'photo': { 'prefix': 'https://igx.4sqi.net/img/user/', 'suffix': '/OTQ3XLHGRYPQIQGR.jpg' } }, 'editable': false, 'public': true, 'collaborative': false, 'url': '/mstrhans/list/holiday', 'canonicalUrl': 'https://foursquare.com/mstrhans/list/holiday', 'createdAt': 1375720158, 'updatedAt': 1377538112, 'followers': { 'count': 1 }, 'listItems': { 'count': 43, 'items': [ { 'id': 'v4c233b549a67a5937ea7dd87', 'createdAt': 1376225268 } ] } } ] } ] }, 'pageUpdates': { 'count': 0, 'items': [] }, 'inbox': { 'count': 0, 'items': [] }, 'venueChains': [], 'attributes': { 'groups': [] }, 'bestPhoto': { 'id': '51878588498e053c231b5333', 'createdAt': 1367836040, 'source': { 'name': 'Instagram', 'url': 'http://instagram.com' }, 'prefix': 'https://igx.4sqi.net/img/general/', 'suffix': '/16198007__KficeTL_D2tiqT7Zgu3wJyiL0485yVS_uNYAtCHOxw.jpg', 'width': 612, 'height': 612, 'visibility': 'public' } }; 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({ '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({ '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(); }); });