mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-21 14:37:47 +00:00
Improve device.getSupportedDevices() to return valid slugs
This commit is contained in:
parent
51c6a8b4c2
commit
77e59cf7b9
10
lib/device/device-data.json
Normal file
10
lib/device/device-data.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"Raspberry Pi": {
|
||||||
|
"slug": "raspberry-pi",
|
||||||
|
"names": [
|
||||||
|
"raspberry-pi",
|
||||||
|
"raspberrypi",
|
||||||
|
"rpi"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"Raspberry Pi": [
|
|
||||||
"raspberry-pi",
|
|
||||||
"raspberrypi",
|
|
||||||
"rpi"
|
|
||||||
]
|
|
||||||
}
|
|
@ -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
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user