Skip to content

Commit

Permalink
fix: [#4204] Fix remaining eslint warnings - Rest of botbuilder-dialo…
Browse files Browse the repository at this point in the history
…gs libraries - botbuilder adaptive testing (#4237)

* Warnings fixed. Missing documentation, unused parameters and imports, disabling detect-non-literal-fs-filename rule and no-constant-condition rule.

* Void changes removed. Unknown type restored to Any. Documentation added.

* api.md file moved to etc folder

* Suggested changes applied.

Co-authored-by: Emiliano Quiroga <emiliano.quiroga@7-11.com>
Co-authored-by: Cecilia Avila <44245136+ceciliaavila@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 13, 2022
1 parent 134d367 commit 0305b7d
Show file tree
Hide file tree
Showing 46 changed files with 320 additions and 221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { StringExpression } from 'adaptive-expressions';
import { TestAdapter } from 'botbuilder-core';
import { TurnContext } from 'botbuilder-core';

// @public (undocumented)
// @public
export class AdaptiveTestBotComponent extends BotComponent {
// (undocumented)
configureServices(services: ServiceCollection, _configuration: Configuration): void;
Expand All @@ -41,10 +41,9 @@ export class AdaptiveTestBotComponent extends BotComponent {
export class AssertCondition<O extends object = {}> extends Dialog<O> implements AssertConditionConfiguration {
// (undocumented)
static $kind: string;
beginDialog(dc: DialogContext, options?: O): Promise<DialogTurnResult>;
beginDialog(dc: DialogContext, _options?: O): Promise<DialogTurnResult>;
condition: Expression;
description: StringExpression;
// (undocumented)
getConverter(property: keyof AssertConditionConfiguration): Converter | ConverterFactory;
// (undocumented)
protected onComputeId(): string;
Expand All @@ -63,7 +62,7 @@ export class AssertNoActivity extends TestAction implements AssertNoActivityConf
// (undocumented)
static $kind: string;
description: string;
execute(adapter: TestAdapter, callback: (context: TurnContext) => Promise<void>, inspector?: Inspector): Promise<void>;
execute(adapter: TestAdapter, _callback: (context: TurnContext) => Promise<void>, _inspector?: Inspector): Promise<void>;
getConditionDescription(): string;
}

Expand All @@ -89,7 +88,7 @@ export class AssertReplyActivity extends TestAction implements AssertReplyActivi
static $kind: string;
assertions: string[];
description: string;
execute(testAdapter: TestAdapter, callback: (context: TurnContext) => Promise<any>, inspector?: Inspector): Promise<any>;
execute(testAdapter: TestAdapter, _callback: (context: TurnContext) => Promise<any>, _inspector?: Inspector): Promise<any>;
getConditionDescription(): string;
timeout: number;
validateReply(activity: Activity): void;
Expand Down Expand Up @@ -137,7 +136,7 @@ export class AssertTelemetryContains extends TestAction implements AssertTelemet
static $kind: string;
description: string;
events: string[];
execute(adapter: TestAdapter, callback: (context: TurnContext) => Promise<void>, inspector?: Inspector): Promise<void>;
execute(_adapter: TestAdapter, _callback: (context: TurnContext) => Promise<void>, inspector?: Inspector): Promise<void>;
}

// @public (undocumented)
Expand All @@ -148,11 +147,11 @@ export interface AssertTelemetryContainsConfiguration {
events?: string[];
}

// @public (undocumented)
// @public
class CustomEvent_2<T = unknown> extends TestAction implements CustomEventConfiguration {
// (undocumented)
static $kind: string;
execute(testAdapter: TestAdapter, callback: (context: TurnContext) => Promise<void>, inspector?: Inspector): Promise<void>;
execute(testAdapter: TestAdapter, callback: (context: TurnContext) => Promise<void>, _inspector?: Inspector): Promise<void>;
name: string;
value?: T;
}
Expand Down Expand Up @@ -188,7 +187,7 @@ export class MemoryAssertions extends TestAction implements MemoryAssertionsConf
static $kind: string;
assertions: string[];
description: string;
execute(adapter: TestAdapter, callback: (context: TurnContext) => Promise<void>, inspector?: Inspector): Promise<void>;
execute(_adapter: TestAdapter, _callback: (context: TurnContext) => Promise<void>, inspector?: Inspector): Promise<void>;
}

// @public (undocumented)
Expand Down Expand Up @@ -229,7 +228,6 @@ export class MockLuisRecognizer extends Recognizer {
export class MockSettingsMiddleware implements Middleware {
// Warning: (ae-forgotten-export) The symbol "SettingMock" needs to be exported by the entry point index.d.ts
constructor(settingMocks: SettingMock[]);
// (undocumented)
onTurn(context: TurnContext, next: () => Promise<void>): Promise<void>;
}

Expand All @@ -238,7 +236,7 @@ export class SetProperties extends TestAction {
// (undocumented)
static $kind: string;
assignments: PropertyAssignment[];
execute(adapter: TestAdapter, callback: (context: TurnContext) => Promise<void>, inspector?: Inspector): Promise<void>;
execute(_adapter: TestAdapter, _callback: (context: TurnContext) => Promise<void>, inspector?: Inspector): Promise<void>;
// (undocumented)
getConverter(property: keyof SetPropertiesConfiguration): Converter | ConverterFactory;
}
Expand Down Expand Up @@ -329,7 +327,7 @@ export interface UserActivityConfiguration {
export class UserConversationUpdate extends TestAction implements UserConversationUpdateConfiguration {
// (undocumented)
static $kind: string;
execute(testAdapter: TestAdapter, callback: (context: TurnContext) => Promise<void>, inspector?: Inspector): Promise<void>;
execute(testAdapter: TestAdapter, callback: (context: TurnContext) => Promise<void>, _inspector?: Inspector): Promise<void>;
membersAdded: string[];
membersRemoved: string[];
}
Expand All @@ -346,7 +344,7 @@ export interface UserConversationUpdateConfiguration {
export class UserDelay extends TestAction implements UserDelayConfiguration {
// (undocumented)
static $kind: string;
execute(testAdapter: TestAdapter, callback: (context: TurnContext) => Promise<any>, inspector?: Inspector): Promise<void>;
execute(_testAdapter: TestAdapter, _callback: (context: TurnContext) => Promise<any>, _inspector?: Inspector): Promise<void>;
timespan: number;
}

Expand All @@ -360,7 +358,7 @@ export interface UserDelayConfiguration {
export class UserSays extends TestAction implements UserSaysConfiguration {
// (undocumented)
static $kind: string;
execute(testAdapter: TestAdapter, callback: (context: TurnContext) => Promise<void>, inspector?: Inspector): Promise<void>;
execute(testAdapter: TestAdapter, callback: (context: TurnContext) => Promise<void>, _inspector?: Inspector): Promise<void>;
locale: string;
text: string;
user: string;
Expand All @@ -378,7 +376,7 @@ export interface UserSaysConfiguration {
export class UserTyping extends Configurable implements TestAction, UserTypingConfiguration {
// (undocumented)
static $kind: string;
execute(testAdapter: TestAdapter, callback: (context: TurnContext) => Promise<any>, inspector?: Inspector): Promise<any>;
execute(testAdapter: TestAdapter, callback: (context: TurnContext) => Promise<any>, _inspector?: Inspector): Promise<any>;
user: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export class AssertCondition<O extends object = {}> extends Dialog<O> implements
*/
description: StringExpression;

/**
* Description of assertion.
*
* @param property Properties that extend RecognizerConfiguration.
* @returns Expression converter.
*
*/
getConverter(property: keyof AssertConditionConfiguration): Converter | ConverterFactory {
switch (property) {
case 'condition':
Expand All @@ -50,11 +57,12 @@ export class AssertCondition<O extends object = {}> extends Dialog<O> implements

/**
* Called when the dialog is started and pushed onto the dialog stack.
*
* @param dc The DialogContext for the current turn of the conversation.
* @param options Additional information to pass to the prompt being started.
* @param _options Additional information to pass to the prompt being started.
* @returns A Promise representing the asynchronous operation.
*/
async beginDialog(dc: DialogContext, options?: O): Promise<DialogTurnResult> {
async beginDialog(dc: DialogContext, _options?: O): Promise<DialogTurnResult> {
const { value } = this.condition.tryEvaluate(dc.state);
if (!value) {
let desc = this.description && this.description.getValue(dc.state);
Expand All @@ -68,6 +76,7 @@ export class AssertCondition<O extends object = {}> extends Dialog<O> implements

/**
* @protected
* @returns String of the condition which must be true.
*/
protected onComputeId(): string {
return `AssertCondition[${this.condition.toString()}]`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ import { SettingStringMock } from './settingMocks/settingStringMock';
import { TestScript } from './testScript';
import { UserTokenBasicMock } from './userTokenMocks';

/**
* Adaptive Testing of BotComponent.
*/
export class AdaptiveTestBotComponent extends BotComponent {
/**
* @param services Services collection to mimic dependency injection.
* @param _configuration Configuration for the bot component.
*/
configureServices(services: ServiceCollection, _configuration: Configuration): void {
services.composeFactory<ComponentDeclarativeTypes[]>('declarativeTypes', (declarativeTypes) =>
declarativeTypes.concat({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class DialogInspector {
}

if (!this.conversationState) {
throw new Error(`The bot's 'conversationState' has not been configured.`);
throw new Error("The bot's 'conversationState' has not been configured.");
}
botStateSet.add(this.conversationState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import { Configurable, Converter } from 'botbuilder-dialogs';
import { ResourceExplorer } from 'botbuilder-dialogs-declarative';

/**
* Base class for all http request mocks.
*/
export abstract class HttpRequestMock extends Configurable {
abstract setup(): void;
}
Expand All @@ -17,8 +20,15 @@ export abstract class HttpRequestMock extends Configurable {
* The type converters for UserTokenMock.
*/
export class HttpRequestMocksConverter implements Converter<string[], HttpRequestMock[]> {
/**
* @param _resourceExplorer The resource to access the content.
*/
constructor(private readonly _resourceExplorer: ResourceExplorer) {}

/**
* @param value Array of strings and Setting Mock elements.
* @returns Array of Setting Mocks.
*/
convert(value: (string | HttpRequestMock)[]): HttpRequestMock[] {
return value.map((item: string | HttpRequestMock) => {
if (typeof item === 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export class MockHttpRequestMiddleware implements Middleware {
this._httpRequestMocks = httpRequestMocks;
}

/**
* @param context The context object for this turn.
* @param next The delegate to call to continue the bot middleware pipeline.
*/
async onTurn(context: TurnContext, next: () => Promise<void>): Promise<void> {
context.turnState.set(MockHttpRequestMiddlewareKey, this);
await next();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable security/detect-non-literal-fs-filename */
/**
* @module botbuilder-dialogs-adaptive-testing
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export class MockLuisLoader implements CustomDeserializer<MockLuisRecognizer, Lu
*/
constructor(private _resourceExplorer: ResourceExplorer, private _configuration?: Record<string, string>) {}

/**
* @param config Config to recognize intents and entities in a users utterance.
* @param type Cached LUIS responses for testing.
* @returns The new object created from the object parameter.
*/
load(config: LuisAdaptiveRecognizerConfiguration, type: Newable<MockLuisRecognizer>): MockLuisRecognizer {
const recognizer = new LuisAdaptiveRecognizer().configure(config as Record<string, unknown>);
const externalEntityRecognizer = config.externalEntityRecognizer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable security/detect-non-literal-fs-filename */
/**
* @module botbuilder-dialogs-adaptive-testing
*/
Expand Down Expand Up @@ -73,6 +74,13 @@ export class MockLuisRecognizer extends Recognizer {
}
}

/**
* @param dialogContext Dialog context.
* @param activity Activity to recognize.
* @param telemetryProperties Additional properties to be logged to telemetry with the LuisResult event.
* @param telemetryMetrics Additional metrics to be logged to telemetry with the LuisResult event.
* @returns Analysis of utterance.
*/
async recognize(
dialogContext: DialogContext,
activity: Activity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export class MockSettingsMiddleware implements Middleware {
});
}

/**
* Processes an incoming activity.
*
* @param context The context object for this turn.
* @param next The delegate to call to continue the bot middleware pipeline.
*/
async onTurn(context: TurnContext, next: () => Promise<void>): Promise<void> {
if (!this._configured) {
if (this._mockData.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import { Middleware, TurnContext, ActivityTypes } from 'botbuilder-core';

const CONVERSATION_STATE = 'ConversationState';

/**
* Middleware that catch "SetTestOptions" event and save into "Conversation.TestOptions".
*/
export class SetTestOptionsMiddleware implements Middleware {
/**
* Processes an incoming event activity.
*
* @param context The context object for this turn.
* @param next The delegate to call to continue the bot middleware pipeline
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ export abstract class SettingMock extends Configurable {}
* The type converters for SettingMock.
*/
export class SettingMocksConverter implements Converter<string[], SettingMock[]> {
/**
* @param _resourceExplorer Parameter to access content resources.
*/
constructor(private readonly _resourceExplorer: ResourceExplorer) {}

/**
* @param value Array of strings and Setting Mock elements.
* @returns Array of Setting Mocks.
*/
convert(value: (string | SettingMock)[]): SettingMock[] {
return value.map((item: string | SettingMock) => {
if (typeof item === 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ export class AssertNoActivity extends TestAction implements AssertNoActivityConf
/**
* Execute the test.
*
* @param testAdapter Adapter to execute against.
* @param callback Logic for the bot to use.
* @param inspector Inspector for dialog context.
* @param adapter Adapter to execute against.
* @param _callback Logic for the bot to use.
* @param _inspector Inspector for dialog context.
*/
async execute(
adapter: TestAdapter,
callback: (context: TurnContext) => Promise<void>,
inspector?: Inspector
_callback: (context: TurnContext) => Promise<void>,
_inspector?: Inspector
): Promise<void> {
if (adapter.activeQueue.length > 0) {
throw new Error(this.getConditionDescription());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class AssertReply extends AssertReplyActivity implements AssertReplyConfi

/**
* Gets the text to assert for an activity.
*
* @returns String.
*/
getConditionDescription(): string {
Expand All @@ -40,6 +41,7 @@ export class AssertReply extends AssertReplyActivity implements AssertReplyConfi

/**
* Validates the reply of an activity.
*
* @param activity The activity to verify.
*/
validateReply(activity: Activity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class AssertReplyActivity extends TestAction implements AssertReplyActivi

/**
* Gets the text to assert for an activity.
*
* @returns String.
*/
getConditionDescription(): string {
Expand All @@ -47,6 +48,7 @@ export class AssertReplyActivity extends TestAction implements AssertReplyActivi

/**
* Validates the reply of an activity.
*
* @param activity The activity to verify.
*/
validateReply(activity: Activity): void {
Expand All @@ -64,17 +66,19 @@ export class AssertReplyActivity extends TestAction implements AssertReplyActivi

/**
* Execute the test.
*
* @param testAdapter Adapter to execute against.
* @param callback Logic for the bot to use.
* @param inspector Inspector for dialog context.
* @param _callback Logic for the bot to use.
* @param _inspector Inspector for dialog context.
* @returns A Promise that represents the work queued to execute.
*/
async execute(
testAdapter: TestAdapter,
callback: (context: TurnContext) => Promise<any>,
inspector?: Inspector
_callback: (context: TurnContext) => Promise<any>,
_inspector?: Inspector
): Promise<any> {
const start = new Date();
/* eslint-disable no-constant-condition */
while (true) {
const current = new Date();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class AssertReplyOneOf extends AssertReplyActivity implements AssertReply

/**
* Gets the text to assert for an activity.
*
* @returns String.
*/
getConditionDescription(): string {
Expand All @@ -40,6 +41,7 @@ export class AssertReplyOneOf extends AssertReplyActivity implements AssertReply

/**
* Validates the reply of an activity.
*
* @param activity The activity to verify.
*/
validateReply(activity: Activity): void {
Expand Down
Loading

0 comments on commit 0305b7d

Please sign in to comment.