Skip to content
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

fix(interactions): fix addPluggable API #10250

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this test because adding an invalid pluggable would not throw any error.
It would simply not add the plugin

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