endo-core
Version:
Put some description here
110 lines (89 loc) • 3.31 kB
text/coffeescript
{afterEach, beforeEach, describe, it} = global
{expect} = require 'chai'
sinon = require 'sinon'
fs = require 'fs'
Encryption = require 'meshblu-encryption'
path = require 'path'
request = require 'request'
enableDestroy = require 'server-destroy'
shmock = require 'shmock'
MockStrategy = require '../mock-strategy'
Server = require '../..'
describe 'static schemas', ->
beforeEach (done) ->
= fs.readFileSync "#{__dirname}/../data/private-key.pem", 'utf8'
= Encryption.fromPem
encrypted =
secrets:
credentials:
secret: 'this is secret'
= .encrypt encrypted
= .key.exportKey 'public'
= shmock 0xd00d
enableDestroy
= new MockStrategy name: 'api'
= new MockStrategy name: 'octoblu'
= messageSchema: sinon.stub()
.get '/v2/whoami'
.set 'Authorization', "Basic cGV0ZXI6aS1jb3VsZC1lYXQ="
.reply 200, {
options:
imageUrl: "http://this-is-an-image.exe"
}
.get '/publickey'
.reply 200, {}
serverOptions =
logFn: ->
port: undefined,
disableLogging: true
apiStrategy:
octobluStrategy:
messageHandler:
serviceUrl: 'http://octoblu.xxx'
deviceType: 'endo-endor'
meshbluConfig:
hostname: 'localhost'
protocol: 'http'
port: 0xd00d
uuid: 'peter'
token: 'i-could-eat'
privateKey:
appOctobluHost: 'http://app.octoblu.xxx'
userDeviceManagerUrl: 'http://manage-my.endo'
staticSchemasPath: path.join(__dirname, '../fixtures/schemas')
meshbluPublicKeyUri: 'http://localhost:53261/publickey'
= new Server serverOptions
.run (error) =>
return done error if error?
= .address().port
done()
afterEach (done) ->
.stop done
afterEach (done) ->
.destroy done
describe 'On GET /schemas/non-extant', ->
describe 'When no non-extant.cson or non-extant.json file is available', ->
beforeEach (done) ->
options =
json: true
baseUrl: "http://localhost:#{@server.address().port}"
request.get '/schemas/non-extant', options, (error, , ) =>
done error
it 'should return a 404', ->
expect(.statusCode).to.equal 404, JSON.stringify
it 'should return an error', ->
expect().to.deep.equal {error: 'Could not find a schema for that path'}
describe 'On GET /schemas/configure', ->
describe 'When configure.cson is available at <path>/configure.cson', ->
beforeEach (done) ->
options =
json: true
baseUrl: "http://localhost:#{@server.address().port}"
request.get '/schemas/configure', options, (error, , ) =>
done error
it 'should return a 200', ->
expect(.statusCode).to.equal 200, JSON.stringify
it 'should return the configure schema', ->
expect().to.deep.equal {foo: 'bar'}