Skip to content

Commit

Permalink
chore(tests): finish task recipe and plan tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-smith-nz committed Aug 15, 2017
1 parent 56161ff commit 4f81f6a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
14 changes: 7 additions & 7 deletions tasks/schemas/taskPlan.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "/tasks/taskPlan",
"title": "Task Plan",
"description": "WILL NEED TO FILL IN ONCE #125 HAS BEEN ANSWERED",
"description": "An assignment of the task to an agent",
"type": "object",
"properties": {
"id": {
Expand All @@ -17,13 +17,13 @@
"description": "Person or group or related agents (e.g. admins) being assigned"
},
"taskRecipeId": {
"$ref": "/tasks/taskRecipe#/definitions/id",
"description": "WILL NEED TO FILL IN ONCE #125 HAS BEEN ANSWERED"
"$ref": "/tasks/taskRecipe#/definitions/id",
"description": "Task recipe that this taask plan is related to"
},
"params": {
"type": "object",
"description": ""
}
"params": {
"type": "object",
"description": "Util paramaters"
}
},
"required": [
"assigneeId",
Expand Down
43 changes: 30 additions & 13 deletions tasks/util/validateTaskRecipe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ const ajv = require('ajv')
const { validateSchema } = require('feathers-hooks-common')
const schema = require('../schemas/taskRecipe')

let hookBefore

test.beforeEach(t => {
hookBefore = {
type: 'before',
method: 'create',
params: { provider: 'rest' },
data: mock.mockTaskRecipes.finishPrereqs
}
})
const hookBefore = {
type: 'before',
method: 'create',
params: { provider: 'rest' },
data: mock.mockTaskRecipes.finishPrereqs
}

test('works with simple recipe', (t) => {
try {
Expand All @@ -29,14 +25,35 @@ test('works with simple recipe', (t) => {
})

test('fails with incorrect id', (t) => {
hookBefore.data.id = 'incorrectId'

let hookBeforeLocal = Object.assign({}, hookBefore, {
data: {
...hookBefore.data,
id: 'incorrectId'
}
})
try {
validateSchema(schema, ajv)(hookBefore)
validateSchema(schema, ajv)(hookBeforeLocal)
t.fail('validation passed unexpectedly')
} catch (err) {
t.deepEqual(err.errors, [
"'id' should be equal to one of the allowed values"
])
}
})

test('fails when child task recipes are invalid', (t) => {
let hookBeforeLocal = Object.assign({}, hookBefore, {
data: {
...hookBefore.data,
childTaskRecipes: [{}]
}
})
try {
validateSchema(schema, ajv)(hookBeforeLocal)
t.fail('validation passed unexpectedly')
} catch (err) {
t.deepEqual(err.errors, [
"'childTaskRecipes[0]' should have required property 'id'"
])
}
})

0 comments on commit 4f81f6a

Please sign in to comment.