Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
derstrassi committed Dec 1, 2017
2 parents 85cfdf1 + f66b374 commit b2e0889
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions test/core/middleware.js
Expand Up @@ -20,7 +20,7 @@ describe('Core: Middleware', () => {
})

describe('action preProcessors', () => {
it('I can define a global preProcessor and it can append the connection', async () => {
it('can define a global preProcessor and it can append the connection', async () => {
api.actions.addMiddleware({
name: 'test middleware',
global: true,
Expand All @@ -34,7 +34,7 @@ describe('Core: Middleware', () => {
expect(_preProcessorNote).to.equal('note')
})

it('I can define an async global preProcessor and it can append the connection', async () => {
it('can define an async global preProcessor and it can append the connection', async () => {
api.actions.addMiddleware({
name: 'test middleware',
global: true,
Expand All @@ -49,7 +49,7 @@ describe('Core: Middleware', () => {
expect(_preProcessorNote).to.equal('slept')
})

it('I can define a local preProcessor and it will not append the connection', async () => {
it('can define a local preProcessor and it will not append the connection', async () => {
api.actions.addMiddleware({
name: 'test middleware',
global: false,
Expand All @@ -63,6 +63,48 @@ describe('Core: Middleware', () => {
expect(_preProcessorNote).to.not.exist()
})

describe('midleware can read properties of the action template', () => {
before(() => {
api.actions.versions.authAction = [1]
api.actions.actions.authAction = {
'1': {
name: 'authAction',
description: 'I am a test',
version: 1,
authenticated: true,
run: (data) => {
data.response.thing = 'stuff'
}
}
}
})

after(() => {
delete api.actions.actions.authAction
delete api.actions.versions.authAction
})

it('can read action template properties', async () => {
api.actions.addMiddleware({
name: 'auth middleware',
global: true,
preProcessor: (data) => {
if (data.actionTemplate.authenticated === true) {
data.response.authenticatedAction = true
} else {
data.response.authenticatedAction = false
}
}
})

let randomResponse = await api.specHelper.runAction('randomNumber')
expect(randomResponse.authenticatedAction).to.equal(false)

let authResponse = await api.specHelper.runAction('authAction')
expect(authResponse.authenticatedAction).to.equal(true)
})
})

it('preProcessors with priorities run in the right order', async () => {
// first priority
api.actions.addMiddleware({
Expand Down

0 comments on commit b2e0889

Please sign in to comment.