mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-25 16:31:05 +00:00
652b596c80
We add a bunch of additional unit tests, and also a coverage report using istanbul. The tests are not meant to cover everything, but they're a first attempt at having *some* unit testing on the supervisor. There's much to improve but hopefully it helps catch obvious errors. Change-Type: patch Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
36 lines
976 B
CoffeeScript
36 lines
976 B
CoffeeScript
express = require 'express'
|
|
_ = require 'lodash'
|
|
api = express()
|
|
api.use(require('body-parser').json())
|
|
|
|
api.resinBackend = {
|
|
currentId: 1
|
|
devices: {}
|
|
registerHandler: (req, res) ->
|
|
console.log('/device/register called with ', req.body)
|
|
device = req.body
|
|
device.id = api.resinBackend.currentId++
|
|
api.resinBackend.devices[device.id] = device
|
|
res.status(201).json(device)
|
|
getDeviceHandler: (req, res) ->
|
|
uuid = req.query['$filter']?.match(/uuid eq '(.*)'/)?[1]
|
|
if uuid?
|
|
res.json({ d: _.filter(api.resinBackend.devices, (dev) -> dev.uuid is uuid ) })
|
|
else
|
|
res.json({ d: [] })
|
|
deviceKeyHandler: (req, res) ->
|
|
res.status(200).send(req.body.apiKey)
|
|
}
|
|
|
|
|
|
api.post '/device/register', (req, res) ->
|
|
api.resinBackend.registerHandler(req, res)
|
|
|
|
api.get '/v4/device', (req, res) ->
|
|
api.resinBackend.getDeviceHandler(req, res)
|
|
|
|
api.post '/api-key/device/:deviceId/device-key', (req, res) ->
|
|
api.resinBackend.deviceKeyHandler(req, res)
|
|
|
|
module.exports = api
|