-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop'
- Loading branch information
Showing
19 changed files
with
434 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ script: | |
- npm test | ||
after_script: | ||
- npm run cover | ||
- npm run report-coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './input'; | ||
export * from './run'; | ||
export * from './send'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { put } from 'redux-saga/effects'; | ||
|
||
export const input = function* (data, state, sessionId) { | ||
yield put({ type: 'input', data, state, sessionId }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { put } from 'redux-saga/effects'; | ||
|
||
export const run = function* (flow, data, state, sessionId) { | ||
yield put({ type: 'run', flow, data, state, sessionId }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { put } from 'redux-saga/effects'; | ||
|
||
export const send = function* (data, sessionId) { | ||
yield put({ type: 'send', data, sessionId }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
'use strict'; | ||
|
||
import Test from 'tape'; | ||
|
||
import { Flowchat } from '../dist/lib'; | ||
|
||
Test('test activator', (t) => { | ||
|
||
t.test('activator receives input, state and sessionId', (t) => { | ||
t.plan(3); | ||
const mockInput = Math.random(); | ||
const mockState = {rand: Math.random()}; | ||
const mockSessionId = Math.random(); | ||
const activator = (input, state, sessionId) => { | ||
t.equal(mockInput, input); | ||
t.deepEqual(mockState, state); | ||
t.equal(mockSessionId, sessionId); | ||
} | ||
const reducer = (input, state) => state; | ||
const saga = function* () {}; | ||
const flow = [activator, reducer, saga]; | ||
const bot = new Flowchat(); | ||
bot.flow('/test', ...flow); | ||
bot.input.onNext({ data: mockInput, state: mockState, sessionId: mockSessionId }); | ||
}); | ||
|
||
t.test('send, input and run are restricted flow names', (t) => { | ||
t.plan(3); | ||
const bot = new Flowchat(); | ||
const activator = () => true; | ||
const reducer = (input, state) => state; | ||
const saga = function* () {}; | ||
const mockFlow = [activator, reducer, saga]; | ||
const throw1 = () => bot.flow('send', ...mockFlow); | ||
const throw2 = () => bot.flow('input', ...mockFlow); | ||
const throw3 = () => bot.flow('run', ...mockFlow); | ||
t.throws(throw1); | ||
t.throws(throw2); | ||
t.throws(throw3); | ||
}); | ||
|
||
t.test('flows run when activator returns true', (t) => { | ||
t.plan(1); | ||
const bot = new Flowchat(); | ||
const activator = () => true; | ||
const reducer = (input, state) => state; | ||
const saga = function* () { | ||
t.ok(true); | ||
}; | ||
const flow = [activator, reducer, saga]; | ||
bot.flow('/test', ...flow); | ||
bot.input.onNext({ data: 'test', state: {}, sessionId: 1 }); | ||
}); | ||
|
||
t.test('flows do not run when activator returns false', (t) => { | ||
t.plan(1); | ||
const bot = new Flowchat(); | ||
const activator = () => false; | ||
const reducer = (input, state) => state; | ||
const saga = function* () { | ||
t.ok(false); | ||
}; | ||
const flow = [activator, reducer, saga]; | ||
bot.flow('/test', ...flow); | ||
bot.input.onNext({ data: 'test', state: {}, sessionId: 1 }); | ||
setTimeout(() => { | ||
t.ok(true); | ||
}, 10); | ||
}); | ||
|
||
t.test('flows run when activator returns a promise that resolves to true', (t) => { | ||
t.plan(1); | ||
const bot = new Flowchat(); | ||
const activator = () => { | ||
return new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve(true); | ||
}, 10); | ||
}); | ||
} | ||
const reducer = (input, state) => state; | ||
const saga = function* () { | ||
t.ok(true); | ||
}; | ||
const flow = [activator, reducer, saga]; | ||
bot.flow('/test', ...flow); | ||
bot.input.onNext({ data: 'test', state: {}, sessionId: 1 }); | ||
}); | ||
|
||
t.test('flows do not run when activator returns a promise that resolves to false', (t) => { | ||
t.plan(1); | ||
const bot = new Flowchat(); | ||
const activator = () => { | ||
return new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve(false); | ||
}, 10); | ||
}); | ||
} | ||
const reducer = (input, state) => state; | ||
const saga = function* () { | ||
t.ok(false); | ||
}; | ||
const flow = [activator, reducer, saga]; | ||
bot.flow('/test', ...flow); | ||
bot.input.onNext({ data: 'test', state: {}, sessionId: 1 }); | ||
setTimeout(() => { | ||
t.ok(true); | ||
}, 20); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
import Test from 'tape'; | ||
|
||
import { Flowchat, input as inputEffect } from '../dist/lib'; | ||
|
||
Test('test input effect', (t) => { | ||
|
||
t.test('input effect emulates new chat bot input', (t) => { | ||
t.plan(1); | ||
const bot = new Flowchat(); | ||
|
||
const activator1 = (input) => input === 'one'; | ||
const reducer1 = (input, state) => state; | ||
const saga1 = function* (input, state, sessionId) { | ||
yield inputEffect('two', state, sessionId); | ||
} | ||
const flow1 = [activator1, reducer1, saga1]; | ||
bot.flow('/one', ...flow1); | ||
|
||
const activator2 = (input) => input === 'two'; | ||
const reducer2 = (input, state) => state; | ||
const saga2 = function* () { | ||
t.ok(true); | ||
} | ||
const flow2 = [activator2, reducer2, saga2]; | ||
bot.flow('/two', ...flow2); | ||
|
||
bot.input.onNext({ data: 'one', state: {}, sessionId: 1 }); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
import Test from 'tape'; | ||
|
||
import { Flowchat, run } from '../dist/lib'; | ||
|
||
Test('test run effect', (t) => { | ||
|
||
t.test('run effect unconditionally runs another flow, skipping the activator', (t) => { | ||
t.plan(2); | ||
const bot = new Flowchat(); | ||
let reducer2Run = false; | ||
|
||
const activator1 = (input) => input === 'one'; | ||
const reducer1 = (input, state) => state; | ||
const saga1 = function* (input, state, sessionId) { | ||
yield run('/two', 'test', state, sessionId); | ||
} | ||
const flow1 = [activator1, reducer1, saga1]; | ||
bot.flow('/one', ...flow1); | ||
|
||
const activator2 = () => { | ||
t.ok(!reducer2Run); // this activator should only be run once, at the initial input | ||
reducer2Run = true; | ||
return false; | ||
} | ||
const reducer2 = (input, state) => state; | ||
const saga2 = function* () { | ||
t.ok(true); | ||
} | ||
const flow2 = [activator2, reducer2, saga2]; | ||
bot.flow('/two', ...flow2); | ||
|
||
bot.input.onNext({ data: 'one', state: {}, sessionId: 1 }); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
import Test from 'tape'; | ||
|
||
import { Flowchat, send } from '../dist/lib'; | ||
|
||
Test('test output', (t) => { | ||
|
||
t.test('send effect sends output', (t) => { | ||
t.plan(2); | ||
const bot = new Flowchat(); | ||
const mockOutput = {this: {is: 'a test'}}; | ||
const mockSessionId = Math.random(); | ||
const activator = () => true; | ||
const reducer = (input, state) => state; | ||
const saga = function* (input, state, sessionId) { | ||
yield send(mockOutput, sessionId); | ||
} | ||
const flow = [activator, reducer, saga]; | ||
bot.flow('/test', ...flow); | ||
bot.output.subscribe(({ data, sessionId }) => { | ||
t.deepEqual(data, mockOutput); | ||
t.equal(sessionId, mockSessionId); | ||
}); | ||
bot.input.onNext({ data: 'test', state: {}, sessionId: mockSessionId }); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
import Test from 'tape'; | ||
|
||
import { Flowchat } from '../dist/lib'; | ||
|
||
Test('test flow', (t) => { | ||
|
||
t.test('flows run in order, one after another', (t) => { | ||
t.plan(1); | ||
// TODO: implement | ||
t.ok(true); | ||
}); | ||
|
||
t.test('next flow reducer receives state updated by previous reducer', (t) => { | ||
t.plan(1); | ||
// TODO: implement | ||
t.ok(true); | ||
}); | ||
|
||
}); |
Oops, something went wrong.