Files
zeekayandHanzo Dev 8e48afdd1e The Teams messaging endpoint is async, so the server starts
With botbuilder loading, `node dist/server.js` still stopped before it
listened: restify 12 asserted that the POST /api/messages handler "is
missing a third argument (the "next" callback) but is not an async
function". restify has taken a two-argument handler only when it is async
since version 9, and teams' package had asked for ^11 since it was
written, so the bot never started. The handler is async now and awaits
adapter.process, as Bot Framework's restify samples do.

test/server.test.ts builds the server as `pnpm start` does and listens on a
free port: /healthz answers 200 and an activity with no Bot Framework
token gets 401 from the adapter. With the old handler both cases fail on
that assertion.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-19 09:19:36 -07:00

44 lines
1.4 KiB
TypeScript

import { afterEach, describe, expect, it } from 'vitest';
import type { Server } from 'restify';
import { createServer, MESSAGES_PATH } from '../src/server';
import { loadConfig } from '../src/config';
// The server as `pnpm start` builds it, listening on a free port. This is the
// only suite that loads botbuilder and restify together, which is where the
// bot failed before it ever took a message.
const config = loadConfig({
MICROSOFT_APP_ID: '00000000-0000-0000-0000-000000000000',
MICROSOFT_APP_PASSWORD: 'test-secret',
HANZO_API_KEY: 'sk-test',
});
let server: Server | undefined;
afterEach(() => {
server?.close();
server = undefined;
});
async function listen(): Promise<string> {
server = createServer(config);
await new Promise<void>((resolve) => server!.listen(0, '127.0.0.1', resolve));
return server.url;
}
describe('the messaging server', () => {
it('starts and answers its health check', async () => {
const res = await fetch(`${await listen()}/healthz`);
expect(res.status).toBe(200);
expect(await res.json()).toEqual({ status: 'ok' });
});
it('refuses an activity that carries no Bot Framework token', async () => {
const res = await fetch(`${await listen()}${MESSAGES_PATH}`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ type: 'message', text: 'hi' }),
});
expect(res.status).toBe(401);
});
});