Skip to content

Commit

Permalink
fix(interactions): fix configure default provider (#10215)
Browse files Browse the repository at this point in the history
* fix(interactions): fix configure default provider

* chore: pin @types/lodash version in aws-amplify-angular

Co-authored-by: Sridhar <ashwsrir@bcd07413f71a.ant.amazon.com>
  • Loading branch information
ashwinkumar6 and Sridhar authored Aug 17, 2022
1 parent f54b645 commit d4c3955
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
50 changes: 46 additions & 4 deletions packages/interactions/__tests__/Interactions-unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import { InteractionsClass as Interactions } from '../src/Interactions';
import { AbstractInteractionsProvider } from '../src/Providers';
import { InteractionsOptions } from '../src/types';
import { AWSLexProvider } from '../src/Providers';

(global as any).Response = () => {};
(global as any).Response.prototype.arrayBuffer = (blob: Blob) => {
Expand Down Expand Up @@ -216,7 +217,12 @@ describe('Interactions', () => {
expect.assertions(4);
});

test('Check if default provider is AWSLexProvider', async () => {
test('Configure bot with default provider (AWSLexProvider) using manual config', async () => {
const lexV1ConfigureSpy = jest.spyOn(
AWSLexProvider.prototype,
'configure'
);

const myBot = {
MyBot: {
name: 'MyBot', // default provider 'AWSLexProvider'
Expand All @@ -230,10 +236,46 @@ describe('Interactions', () => {
},
};

expect(interactions.configure(myConfig)).toEqual({
bots: myBot,
interactions.configure(myConfig);

// check if provider's configure was called
expect(lexV1ConfigureSpy).toBeCalledTimes(Object.keys(myBot).length);
expect(lexV1ConfigureSpy).toHaveBeenCalledWith({
MyBot: myBot.MyBot,
});
expect.assertions(1);
expect.assertions(2);
});

test('Configure bot with default provider (AWSLexProvider) using aws-exports config', async () => {
const lexV1ConfigureSpy = jest.spyOn(
AWSLexProvider.prototype,
'configure'
);

const awsmobileBot = {
name: 'BookTripMOBILEHUB',
alias: '$LATEST',
region: 'us-east-1',
description: 'Bot to make reservations for a visit to a city.',
'bot-template': 'bot-trips',
};
const awsmobile = {
aws_bots: 'enable',
aws_bots_config: [awsmobileBot],
aws_project_name: 'bots',
aws_project_region: 'us-east-1',
};

interactions.configure(awsmobile);

// check if provider's configure was called
expect(lexV1ConfigureSpy).toBeCalledTimes(
awsmobile.aws_bots_config.length
);
expect(lexV1ConfigureSpy).toHaveBeenCalledWith({
BookTripMOBILEHUB: awsmobileBot,
});
expect.assertions(2);
});

test('Configure bot belonging to non-existing plugin', async () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/interactions/src/Interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,17 @@ export class InteractionsClass {
Object.keys(bots_config).forEach(botKey => {
const bot = bots_config[botKey];
const providerName = bot.providerName || 'AWSLexProvider';

// add default provider if required
if (
!this._pluggables.AWSLexProvider &&
providerName === 'AWSLexProvider'
) {
this._pluggables.AWSLexProvider = new AWSLexProvider();
} else if (this._pluggables[providerName]) {
}

// configure bot with it's respective provider
if (this._pluggables[providerName]) {
this._pluggables[providerName].configure({ [bot.name]: bot });
} else {
logger.debug(
Expand Down

0 comments on commit d4c3955

Please sign in to comment.