-
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.
Added new ConvoTest class that offers extra features for testing Conv…
…o agents.
- Loading branch information
Showing
4 changed files
with
173 additions
and
75 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
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,34 @@ | ||
|
||
class ConvoTest { | ||
static containsResponseType(requests, types) { | ||
if (!requests) { | ||
throw new Error('Requests were not supplied.'); | ||
} | ||
if (!types || types.length === 0) { | ||
return false; | ||
} | ||
return types | ||
.map(type => requests.filter(request => request.payload.type === type).length > 0) | ||
.filter(typeVal => !typeVal) | ||
.length === 0; | ||
} | ||
static isConversationClose(requests) { | ||
return requests[0] && requests[0].action === 'close'; | ||
} | ||
static testConversation(conversation, done) { | ||
if (!conversation || !conversation.then) { | ||
throw new Error('You must pass a conversational promise.'); | ||
} | ||
if (!done) { | ||
throw new Error('You must pass a done function.'); | ||
} | ||
let isDone = false; | ||
conversation.catch(err => { | ||
isDone = true; | ||
done(err); | ||
}) | ||
.then(() => !isDone && done()); | ||
} | ||
} | ||
|
||
module.exports = { ConvoTest }; |
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
Oops, something went wrong.