UNPKG

fallout4-bobbleheads

Version:

Get fallout4 bobblehead locations and descriptions.

60 lines (49 loc) 2.1 kB
'use strict' const expect = require('chai').expect const FOB = require('./index') const _ = require('lodash') const arrayOfKeys = ['name','type','effect', 'area'] describe('fallout4-bobbleheads', function() { describe('all', function(){ it('should be an array of objects', function(){ expect(FOB.all).to.satisfy(isArrayOfObjects) function isArrayOfObjects(array){ return array.every(function(item){ return typeof item === 'object' }) } }) _.each(arrayOfKeys, function(keyName){ it('should have ' + keyName + ' with value for each bobblehead', function(){ expect(FOB.all).to.satisfy(hasKeyAndValueForEachItem) function hasKeyAndValueForEachItem(array) { return array.every(function(item){ return _.has(item,keyName) && !_.isEmpty(item[keyName]) }) } }) }) }) describe('search', function(){ it('should return empty array if searched words are not in bobbleheads', function(){ expect(FOB.search('NOTFOUND-BOGUSSEARCHITEM-NOTFOUND')).to.be.a('array') expect(FOB.search('NOTFOUND-BOGUSSEARCHITEM-NOTFOUND')).to.be.empty }) it('should return an object with the words if the words are in an object', function(){ let searchWord = 'strength' expect(FOB.search(searchWord)).to.be.not.empty expect(FOB.search(searchWord)).to.be.a('array') expect(FOB.search(searchWord)).to.satisfy(searchWordExists) function searchWordExists(array){ let found = false // console.log(array) _.some(array,function(bobblehead){ _.some(_.values(bobblehead),function(value){ if (_.toLower(value).indexOf(_.toLower(searchWord))!==-1) return found = true }) }) return found } }) }) })