Skip to content
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
17 changes: 17 additions & 0 deletions packages/connector-slack/src/slack-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ function makeAdapter(): {
return { adapter, setStatus, postMessage };
}

describe('SlackAdapter construction', () => {
it('does not throw or reject synchronously when constructed with fake tokens (no network call)', async () => {
// Guard: constructing must be network-free. With deferInitialization:true the
// Bolt App skips the construct-time auth.test() call, so no unhandled rejection fires.
let adapter: SlackAdapter | undefined;
expect(() => {
adapter = new SlackAdapter({
slackBotToken: 'xoxb-test',
slackAppToken: 'xapp-test',
} as never);
}).not.toThrow();
// Flush microtasks to surface any immediate promise rejection.
await Promise.resolve();
expect(adapter).toBeDefined();
});
});

describe('SlackAdapter.postError', () => {
it('posts an errorBlock with the headline as the push fallback text', async () => {
const { adapter, postMessage } = makeAdapter();
Expand Down
7 changes: 7 additions & 0 deletions packages/connector-slack/src/slack-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export class SlackAdapter implements SurfaceAdapter {
token: config.slackBotToken,
appToken: config.slackAppToken,
socketMode: true,
// deferInitialization prevents the Bolt App constructor from making a
// construct-time auth.test() network call. start() calls app.init()
// before app.start() to run the deferred initialization at the right time.
deferInitialization: true,
});
this.wire();
}
Expand All @@ -71,6 +75,9 @@ export class SlackAdapter implements SurfaceAdapter {
}

async start(): Promise<void> {
// init() runs the deferred auth.test() that was skipped in the constructor
// (because deferInitialization:true); start() throws if init() was not called.
await this.app.init();
await this.app.start();
}

Expand Down
Loading