Skip to content

Commit

Permalink
fix(interactions): fix addPluggable API (aws-amplify#10250)
Browse files Browse the repository at this point in the history
* fix(interactions): fix addPluggable API

* fix(interactions): remove Add a invalid pluggable test

Co-authored-by: Sridhar <ashwsrir@bcd07413f71a.ant.amazon.com>
  • Loading branch information
ashwinkumar6 and Sridhar authored Aug 23, 2022
1 parent 2b54c1a commit 01aad60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
7 changes: 0 additions & 7 deletions packages/interactions/__tests__/Interactions-unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,6 @@ describe('Interactions', () => {
expect.assertions(4);
});

test('Add a invalid pluggable', () => {
expect(() => interactions.addPluggable(new WrongProvider())).toThrow(
'Invalid pluggable'
);
expect.assertions(1);
});

test('Add existing pluggable again', () => {
interactions.addPluggable(new DummyProvider());
expect(() => {
Expand Down
44 changes: 21 additions & 23 deletions packages/interactions/src/Interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,27 @@ export class InteractionsClass {
}

public addPluggable(pluggable: InteractionsProvider) {
if (!(pluggable && pluggable.getCategory() === 'Interactions')) {
throw new Error('Invalid pluggable');
}

if (!this._pluggables[pluggable.getProviderName()]) {
// configure bots for the new plugin
Object.keys(this._options.bots)
.filter(
botKey =>
this._options.bots[botKey].providerName ===
pluggable.getProviderName()
)
.forEach(botKey => {
const bot = this._options.bots[botKey];
pluggable.configure({ [bot.name]: bot });
});

this._pluggables[pluggable.getProviderName()] = pluggable;
return;
} else {
throw new Error(
'Pluggable ' + pluggable.getProviderName() + ' already plugged'
);
if (pluggable && pluggable.getCategory() === 'Interactions') {
if (!this._pluggables[pluggable.getProviderName()]) {
// configure bots for the new plugin
Object.keys(this._options.bots)
.filter(
botKey =>
this._options.bots[botKey].providerName ===
pluggable.getProviderName()
)
.forEach(botKey => {
const bot = this._options.bots[botKey];
pluggable.configure({ [bot.name]: bot });
});

this._pluggables[pluggable.getProviderName()] = pluggable;
return;
} else {
throw new Error(
'Pluggable ' + pluggable.getProviderName() + ' already plugged'
);
}
}
}

Expand Down

0 comments on commit 01aad60

Please sign in to comment.