|
3 | 3 | import { describe, it, beforeEach, afterEach } from 'node:test' |
4 | 4 | import assert from 'node:assert/strict' |
5 | 5 | import path from 'node:path' |
6 | | -import { Robot, CatchAllMessage, EnterMessage, LeaveMessage, TextMessage, TopicMessage, User } from '../index.mjs' |
| 6 | +import { Robot, CatchAllMessage, EnterMessage, LeaveMessage, TextMessage, TopicMessage, User, Response } from '../index.mjs' |
7 | 7 | import mockAdapter from './fixtures/MockAdapter.mjs' |
8 | 8 | describe('Robot', () => { |
9 | 9 | describe('#http', () => { |
@@ -204,11 +204,30 @@ describe('Robot', () => { |
204 | 204 | it('sends a CatchAllMessage if no listener matches', async () => { |
205 | 205 | const testMessage = new TextMessage(user, 'message123') |
206 | 206 | robot.listeners = [] |
| 207 | + let actual = null |
207 | 208 | robot.catchAll(async (message) => { |
208 | | - assert.ok(message instanceof CatchAllMessage) |
209 | | - assert.deepEqual(message.message, testMessage) |
| 209 | + actual = message |
210 | 210 | }) |
211 | 211 | await robot.receive(testMessage) |
| 212 | + assert.ok(actual.message instanceof CatchAllMessage) |
| 213 | + assert.deepEqual(actual.message.message, testMessage) |
| 214 | + }) |
| 215 | + |
| 216 | + it('calls the catch-all listener with a Response object', async () => { |
| 217 | + const testMessage = new TextMessage(user, 'message123') |
| 218 | + |
| 219 | + const listenerCallback = async () => { |
| 220 | + assert.fail('Should not have called listener') |
| 221 | + } |
| 222 | + robot.hear(/^no-matches$/, listenerCallback) |
| 223 | + let actual = null |
| 224 | + robot.catchAll(async response => { |
| 225 | + response.reply('caught by catchAll') |
| 226 | + actual = response |
| 227 | + }) |
| 228 | + |
| 229 | + await robot.receive(testMessage) |
| 230 | + assert.ok(actual instanceof Response) |
212 | 231 | }) |
213 | 232 |
|
214 | 233 | it('does not trigger a CatchAllMessage if a listener matches', async () => { |
@@ -572,7 +591,7 @@ describe('Robot', () => { |
572 | 591 | robot.hear(/^no-matches$/, listenerCallback) |
573 | 592 |
|
574 | 593 | robot.catchAll(async response => { |
575 | | - assert.deepEqual(response.message, testMessage) |
| 594 | + assert.deepEqual(response.message.message, testMessage) |
576 | 595 | }) |
577 | 596 |
|
578 | 597 | await robot.receive(testMessage) |
|
0 commit comments