Improve device.getSupportedDevices() to return valid slugs

This commit is contained in:
Juan Cruz Viotti 2014-11-24 08:54:35 -04:00
parent 51c6a8b4c2
commit 77e59cf7b9
4 changed files with 25 additions and 12 deletions

View File

@ -0,0 +1,10 @@
{
"Raspberry Pi": {
"slug": "raspberry-pi",
"names": [
"raspberry-pi",
"raspberrypi",
"rpi"
]
}
}

View File

@ -1,7 +0,0 @@
{
"Raspberry Pi": [
"raspberry-pi",
"raspberrypi",
"rpi"
]
}

View File

@ -1,11 +1,12 @@
_ = require('lodash') _ = require('lodash')
DEVICE_NAMES = require('./device-names.json') DEVICES = require('./device-data.json')
exports.getDisplayName = (device) -> exports.getDisplayName = (device) ->
for key, value of DEVICE_NAMES for key, value of DEVICES
if _.indexOf(value, device) isnt -1 if _.indexOf(value.names, device) isnt -1
return key return key
return 'Unknown' return 'Unknown'
exports.getSupportedDevices = -> exports.getSupportedDevices = ->
return _.keys(DEVICE_NAMES) return _.map DEVICES, (device) ->
return device.slug

View File

@ -1,5 +1,6 @@
expect = require('chai').expect expect = require('chai').expect
device = require('./device') device = require('./device')
DEVICES = require('./device-data.json')
describe 'Device:', -> describe 'Device:', ->
@ -28,6 +29,14 @@ describe 'Device:', ->
describe '#getSupportedDevices()', -> describe '#getSupportedDevices()', ->
it 'should return an array', -> result = null
beforeEach ->
result = device.getSupportedDevices() result = device.getSupportedDevices()
it 'should return an array', ->
expect(result).to.be.an.instanceof(Array) expect(result).to.be.an.instanceof(Array)
it 'should return all slugs', ->
for device in DEVICES
expect(result.indexOf(device.slug)).to.not.equal(-1)