Skip to content

Commit c57541a

Browse files
committed
feat(queue): add QueueManager fake helpers
1 parent 59556a0 commit c57541a

File tree

6 files changed

+940
-0
lines changed

6 files changed

+940
-0
lines changed

.changelog/queue-fake.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Queue testing improvements
2+
3+
## New feature
4+
5+
### QueueManager.fake / QueueManager.restore
6+
7+
You can replace all adapters with the fake adapter for test assertions, then restore the original configuration.
8+
9+
```typescript
10+
import { QueueManager } from '@boringnode/queue'
11+
import { redis } from '@boringnode/queue/drivers/redis_adapter'
12+
13+
await QueueManager.init({
14+
default: 'redis',
15+
adapters: {
16+
redis: redis({ host: 'localhost' }),
17+
},
18+
})
19+
20+
const fake = QueueManager.fake()
21+
22+
await SendEmailJob.dispatch({ to: '[email protected]' })
23+
24+
fake.assertPushed('SendEmailJob', {
25+
queue: 'default',
26+
payload: { to: '[email protected]' },
27+
})
28+
29+
QueueManager.restore()
30+
```

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,34 @@ The adapter automatically creates tables on first use.
215215

216216
</details>
217217

218+
### Fake (testing + assertions)
219+
220+
```typescript
221+
import { QueueManager } from '@boringnode/queue'
222+
import { redis } from '@boringnode/queue/drivers/redis_adapter'
223+
224+
await QueueManager.init({
225+
default: 'redis',
226+
adapters: {
227+
redis: redis({ host: 'localhost' }),
228+
},
229+
locations: ['./app/jobs/**/*.ts'],
230+
})
231+
232+
const adapter = QueueManager.fake()
233+
234+
await SendEmailJob.dispatch({ to: '[email protected]' })
235+
236+
adapter.assertPushed('SendEmailJob')
237+
adapter.assertPushed('SendEmailJob', {
238+
queue: 'default',
239+
payload: (payload) => payload.to === '[email protected]',
240+
})
241+
adapter.assertPushedCount(1)
242+
243+
QueueManager.restore()
244+
```
245+
218246
### Sync (for testing)
219247

220248
```typescript

0 commit comments

Comments
 (0)