Skip to content

Commit

Permalink
fix: use no-op configuration for configure services calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Gummersall committed Mar 27, 2021
1 parent 0469d4c commit f5c75c0
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AdaptiveTeamsBotComponent } from '../src/adaptiveTeamsBotComponent';
import { AdaptiveTestBotComponent, TestUtils } from 'botbuilder-dialogs-adaptive-testing';
import { ConnectorClient, MicrosoftAppCredentials } from 'botframework-connector';
import { ComponentDeclarativeTypes, ResourceExplorer } from 'botbuilder-dialogs-declarative';
import { Configuration, ServiceCollection } from 'botbuilder-runtime-core';
import { ServiceCollection, noOpConfiguration } from 'botbuilder-runtime-core';
import { jwt } from 'botbuilder-test-utils';
import { ok } from 'assert';

Expand Down Expand Up @@ -125,16 +125,9 @@ describe('Actions', function () {
declarativeTypes: [],
});

const configuration: Configuration = {
get(_path) {
return undefined;
},
set(_path, _value) {},
};

new AdaptiveBotComponent().configureServices(services, configuration);
new AdaptiveTeamsBotComponent().configureServices(services, configuration);
new AdaptiveTestBotComponent().configureServices(services, configuration);
new AdaptiveBotComponent().configureServices(services, noOpConfiguration);
new AdaptiveTeamsBotComponent().configureServices(services, noOpConfiguration);
new AdaptiveTestBotComponent().configureServices(services, noOpConfiguration);

const declarativeTypes = services.mustMakeInstance<ComponentDeclarativeTypes[]>('declarativeTypes');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AdaptiveBotComponent } from 'botbuilder-dialogs-adaptive';
import { AdaptiveTeamsBotComponent } from '../src';
import { AdaptiveTestBotComponent, TestUtils } from 'botbuilder-dialogs-adaptive-testing';
import { ComponentDeclarativeTypes, ResourceExplorer } from 'botbuilder-dialogs-declarative';
import { Configuration, ServiceCollection } from 'botbuilder-runtime-core';
import { ServiceCollection, noOpConfiguration } from 'botbuilder-runtime-core';

describe('Conditional Tests', function () {
let resourceExplorer: ResourceExplorer;
Expand All @@ -15,16 +15,9 @@ describe('Conditional Tests', function () {
declarativeTypes: [],
});

const configuration: Configuration = {
get(_path) {
return undefined;
},
set(_path, _value) {},
};

new AdaptiveBotComponent().configureServices(services, configuration);
new AdaptiveTeamsBotComponent().configureServices(services, configuration);
new AdaptiveTestBotComponent().configureServices(services, configuration);
new AdaptiveBotComponent().configureServices(services, noOpConfiguration);
new AdaptiveTeamsBotComponent().configureServices(services, noOpConfiguration);
new AdaptiveTestBotComponent().configureServices(services, noOpConfiguration);

const declarativeTypes = services.mustMakeInstance<ComponentDeclarativeTypes[]>('declarativeTypes');

Expand Down
8 changes: 4 additions & 4 deletions libraries/botbuilder-dialogs-adaptive-testing/tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ const path = require('path');
const { AdaptiveBotComponent } = require('botbuilder-dialogs-adaptive');
const { AdaptiveTestBotComponent } = require('..');
const { ResourceExplorer } = require('botbuilder-dialogs-declarative');
const { ServiceCollection } = require('botbuilder-runtime-core');
const { ServiceCollection, noOpConfiguration } = require('botbuilder-runtime-core');

function makeResourceExplorer(resourceFolder, ...botComponents) {
const services = new ServiceCollection({
declarativeTypes: [],
});

new AdaptiveBotComponent().configureServices(services, null);
new AdaptiveTestBotComponent().configureServices(services, null);
new AdaptiveBotComponent().configureServices(services, noOpConfiguration);
new AdaptiveTestBotComponent().configureServices(services, noOpConfiguration);

botComponents.forEach((BotComponent) => {
new BotComponent().configureServices(services, null);
new BotComponent().configureServices(services, noOpConfiguration);
});

const declarativeTypes = services.mustMakeInstance('declarativeTypes');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const { ResourceExplorer } = require('../lib');
const { DialogManager } = require('botbuilder-dialogs');
const { QnACardBuilder, RankerTypes, QnAMakerClientKey, QnAMakerBotComponent } = require('botbuilder-ai');
const { ServiceCollection } = require('botbuilder-runtime-core');
const { ServiceCollection, noOpConfiguration } = require('botbuilder-runtime-core');
const { StringExpression } = require('adaptive-expressions');

const {
Expand Down Expand Up @@ -142,8 +142,8 @@ describe('Json load tests', function () {
declarativeTypes: [],
});

new AdaptiveBotComponent().configureServices(services, null);
new QnAMakerBotComponent().configureServices(services, null);
new AdaptiveBotComponent().configureServices(services, noOpConfiguration);
new QnAMakerBotComponent().configureServices(services, noOpConfiguration);

const declarativeTypes = services.mustMakeInstance('declarativeTypes');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const assert = require('assert');
const { AdaptiveBotComponent } = require('botbuilder-dialogs-adaptive');
const { DialogManager } = require('botbuilder-dialogs');
const { ResourceExplorer, FolderResourceProvider, ResourceChangeEvent } = require('../lib');
const { ServiceCollection } = require('botbuilder-runtime-core');
const { ServiceCollection, noOpConfiguration } = require('botbuilder-runtime-core');
const { TestAdapter, MemoryStorage, useBotState, UserState, ConversationState } = require('botbuilder-core');
const { extname, join } = require('path');
const { writeFileSync, existsSync, unlinkSync } = require('fs');
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('ResourceExplorer', function () {
declarativeTypes: [],
});

new AdaptiveBotComponent().configureServices(services, null);
new AdaptiveBotComponent().configureServices(services, noOpConfiguration);

const declarativeTypes = services.mustMakeInstance('declarativeTypes');
const explorer = new ResourceExplorer({ declarativeTypes }).addFolders(join(__dirname, 'resources'), [], false);
Expand Down Expand Up @@ -269,7 +269,7 @@ describe('ResourceExplorer', function () {
declarativeTypes: [],
});

new AdaptiveBotComponent().configureServices(services, null);
new AdaptiveBotComponent().configureServices(services, noOpConfiguration);

const declarativeTypes = services.mustMakeInstance('declarativeTypes');
const resourceExplorer = new ResourceExplorer({ declarativeTypes }).addFolder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { ComponentRegistration } from 'botbuilder-core';
import { ServiceCollection } from 'botbuilder-runtime-core';
import { ServiceCollection, noOpConfiguration } from 'botbuilder-runtime-core';
import { DialogsBotComponent } from './dialogsBotComponent';
import { ComponentMemoryScopes, ComponentPathResolvers, MemoryScope, PathResolver } from './memory';

Expand All @@ -25,7 +25,7 @@ export class DialogsComponentRegistration
constructor() {
super();

new DialogsBotComponent().configureServices(this.services, null);
new DialogsBotComponent().configureServices(this.services, noOpConfiguration);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Licensed under the MIT License.
*/

import { Configuration } from 'botbuilder-runtime-core';
import { DialogContext } from '../../dialogContext';
import { DialogTurnStateConstants } from '../../dialogTurnStateConstants';
import { MemoryScope } from './memoryScope';
Expand Down
10 changes: 10 additions & 0 deletions libraries/botbuilder-runtime-core/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ export interface Configuration {
*/
set(path: string[], value: unknown): void;
}

// noOpConfiguration is useful for shimming new BotComponents back to ComponentRegistrations
export const noOpConfiguration: Configuration = {
get(_path: string[]): unknown | undefined {
return undefined;
},
set(_path: string[], _value: unknown): void {
// no-op
},
};
5 changes: 5 additions & 0 deletions libraries/botbuilder-runtime/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export class Configuration implements CoreConfiguration {
* @returns the value, or undefined
*/
get(path: string[]): unknown | undefined {
// Note: empty path should yield the entire configuration
if (!path.length) {
return this.provider.get();
}

return this.provider.get(this.key(path));
}

Expand Down

0 comments on commit f5c75c0

Please sign in to comment.