-
Notifications
You must be signed in to change notification settings - Fork 11
[ARO] Adding a feature to make tester able to create their own test #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,5 @@ yarn-error.log | |
| .coveralls.yml | ||
| .nyc_output | ||
| coverage | ||
| *.ava.spec.js | ||
| *.ava.spec.js | ||
| .idea | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,19 @@ | ||
| import { IEvent, IMessage } from 'botbuilder'; | ||
| import { BotTesterExpectation } from './assertionLibraries/BotTesterExpectation'; | ||
| import { IConfig } from './config'; | ||
| import {IEvent, IMessage} from 'botbuilder'; | ||
| import {assert} from 'chai'; | ||
| import {BotTesterExpectation} from './assertionLibraries/BotTesterExpectation'; | ||
| import {IConfig} from './config'; | ||
|
|
||
| export enum ExpectedMessageType { | ||
| String, | ||
| IMessage, | ||
| Regex | ||
| Regex, | ||
| Function | ||
| } | ||
|
|
||
| /** | ||
| * Types accepted for responses checkers | ||
| */ | ||
| export type PossibleExpectedMessageType = string | IMessage | RegExp | IEvent; | ||
| export type PossibleExpectedMessageType = string | IMessage | RegExp | IEvent | Function; | ||
|
|
||
| /** | ||
| * Response expectations area always collections. The collection is the set of possible responses, chosen at random. If the collection size | ||
|
|
@@ -26,6 +28,8 @@ function getExpectedMessageType(expectedResponseCollection: PossibleExpectedMess | |
| return ExpectedMessageType.String; | ||
| } else if (firstElt.constructor.name === 'RegExp') { | ||
| return ExpectedMessageType.Regex; | ||
| } else if (firstElt.constructor.name === 'Function') { | ||
| return ExpectedMessageType.Function; | ||
| } else { | ||
| return ExpectedMessageType.IMessage; | ||
| } | ||
|
|
@@ -42,10 +46,8 @@ export class ExpectedMessage { | |
| */ | ||
| private readonly expectedResponseCollection: PossibleExpectedMessageCollections; | ||
|
|
||
| constructor( | ||
| config: IConfig, | ||
| expectedResponseCollection: PossibleExpectedMessageType | PossibleExpectedMessageCollections | ||
| ) { | ||
| constructor(config: IConfig, | ||
| expectedResponseCollection: PossibleExpectedMessageType | PossibleExpectedMessageCollections) { | ||
| this.internalExpectation = new BotTesterExpectation(config); | ||
|
|
||
| if (!(expectedResponseCollection instanceof Array)) { | ||
|
|
@@ -73,6 +75,9 @@ export class ExpectedMessage { | |
| // doing this check will highlight if the diff in text instead of a large IMessage diff | ||
| this.deepMessageMatchCheck(outgoingMessage); | ||
| break; | ||
| case ExpectedMessageType.Function: | ||
| this.deepMatchCheckWithFunction(outgoingMessage); | ||
| break; | ||
| default: | ||
| this.internalExpectation.expect(outgoingMessage.type).toEqual('save'); | ||
| } | ||
|
|
@@ -111,7 +116,7 @@ export class ExpectedMessage { | |
| const regexCollection: RegExp[] = this.expectedResponseCollection as RegExp[]; | ||
|
|
||
| this.internalExpectation.expect(regexCollection.some((regex: RegExp) => regex.test(text)), | ||
| `'${text}' did not match any regex in ${regexCollection}`).toBeTrue(); | ||
| `'${text}' did not match any regex in ${regexCollection}`).toBeTrue(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -136,4 +141,30 @@ export class ExpectedMessage { | |
|
|
||
| this.internalExpectation.expect(expectedResponseCollectionAsIMessage).toDeeplyInclude(outgoingMessage); | ||
| } | ||
|
|
||
| /** | ||
| * Verfy the incoming message with custom test defined by tester | ||
| * If the function that tester defined return an error, make the test break | ||
| * If the function return anything else, the test is considered as good | ||
| * I've tryed to use promise as parameter, but in a promise we change scope, so the assert doesn't work | ||
| * @param {IMessage} outgoingMessage outgoing message being compared | ||
| */ | ||
| private deepMatchCheckWithFunction(outgoingMessage: IMessage): void { | ||
| const functionCollection: Function[] = this.expectedResponseCollection as Function[]; | ||
| let errorString = ''; | ||
| let success = false; | ||
| functionCollection.forEach((func: Function) => { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you tried bluebird
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but we are in the promise context, the "this.internalExpectation.expect(success, error).toBeTrue();" create an error but test still a success |
||
| const result = func(outgoingMessage); | ||
| if (result instanceof Error) { | ||
| errorString += `\n -----------------ERROR-----------------\n\n\n'${result.message}' `; | ||
| } else { | ||
| success = true; | ||
| } | ||
| }); | ||
| // ErrorString here, can hold multiples error, if the bot send multiples message in one batching | ||
| const error = `Bot should have relied response that matches with function but respond '${outgoingMessage}'` + | ||
| ` that create the following error(s) '${errorString}'`; | ||
| this.internalExpectation.expect(success, error).toBeTrue(); | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| --require ts-node/register | ||
| --recursive | ||
| test/*.spec.ts | ||
| test/**/*mocha.spec.ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] spelling error
tryed->tried