Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Radchenko committed Sep 16, 2016
1 parent 7a5242d commit b890daa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
16 changes: 12 additions & 4 deletions dist/index.js
Expand Up @@ -21,10 +21,16 @@ module.exports = class Runner {
*
*/
start() {return __async(function*(){
const startTask = this.getTask(this.workflow.startTaskId)
const startTaskId = this.workflow.startTaskId

if (!startTaskId) {
throw new Error('`startTaskId` must be specified')
}

const startTask = this.getTask(startTaskId)

if (!startTask) {
throw new Error('Invalid workflow - missing start task')
throw new Error('Invalid workflow - start task not found')
}

yield this.runTask(startTask)
Expand Down Expand Up @@ -106,10 +112,12 @@ module.exports = class Runner {
}.call(this))}

getTask(id, source) {
source = source || this.workflow.tasks
source = source || this.workflow.tasks || {}
const task = source[id]

task._id = id
if (task) {
task._id = id
}

return task
}
Expand Down
16 changes: 12 additions & 4 deletions lib/index.js
Expand Up @@ -21,10 +21,16 @@ module.exports = class Runner {
*
*/
async start() {
const startTask = this.getTask(this.workflow.startTaskId)
const startTaskId = this.workflow.startTaskId

if (!startTaskId) {
throw new Error('`startTaskId` must be specified')
}

const startTask = this.getTask(startTaskId)

if (!startTask) {
throw new Error('Invalid workflow - missing start task')
throw new Error('Invalid workflow - start task not found')
}

await this.runTask(startTask)
Expand Down Expand Up @@ -106,10 +112,12 @@ module.exports = class Runner {
}

getTask(id, source) {
source = source || this.workflow.tasks
source = source || this.workflow.tasks || {}
const task = source[id]

task._id = id
if (task) {
task._id = id
}

return task
}
Expand Down
14 changes: 14 additions & 0 deletions test/index.js
Expand Up @@ -10,6 +10,20 @@ test('requires workflow', t => {
}, 'Invalid workflow specified', 'Throws on invalid workflow')
})

test('workflow requires startTaskId', async t => {
const runner = new Runner({})

t.throws(runner.start(), '`startTaskId` must be specified',
'Throws on invalid')
})

test('workflow requires startTask', async t => {
const runner = new Runner({startTaskId: 'a'})

t.throws(runner.start(), 'Invalid workflow - start task not found',
'Throws on invalid')
})

test('All pass', async t => {
const workflow = require('./fixtures/all-pass')

Expand Down

0 comments on commit b890daa

Please sign in to comment.