-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
78 lines (61 loc) · 2.25 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict'
const test = require('ava')
const Queue = require('bee-queue')
const { fastifyBeeQueue } = require('./')
const TEST_QUEUE_NAME = 'test-queue'
test('"create" creates a worker Queue instance', async (t) => {
const app = require('fastify')()
app.register(fastifyBeeQueue)
await app.ready()
const q = await app.bq.create(TEST_QUEUE_NAME)
t.true(q instanceof Queue)
t.true(q.settings.isWorker)
t.true(q.settings.getEvents)
})
test('createProducer creates a producer Queue instance', async (t) => {
const app = require('fastify')()
app.register(fastifyBeeQueue)
await app.ready()
const q = await app.bq.createProducer(TEST_QUEUE_NAME)
t.true(q instanceof Queue)
t.false(q.settings.isWorker)
t.false(q.settings.getEvents)
})
test('"createProducer" registers Queue instances in the queues object', async (t) => {
const app = require('fastify')()
app.register(fastifyBeeQueue)
await app.ready()
await app.bq.createProducer(TEST_QUEUE_NAME)
const q = app.bq.queues[TEST_QUEUE_NAME]
t.true(q instanceof Queue)
t.false(q.settings.isWorker)
t.false(q.settings.getEvents)
})
test('"create" registers Queue instances in the queues object', async (t) => {
const app = require('fastify')()
app.register(fastifyBeeQueue)
await app.ready()
await app.bq.create(TEST_QUEUE_NAME)
const q = app.bq.queues[TEST_QUEUE_NAME]
t.true(q instanceof Queue)
t.true(q.settings.isWorker)
t.true(q.settings.getEvents)
})
test('"create": Cannot override existing stored Queues in the queues decorator', async (t) => {
const app = require('fastify')()
app.register(fastifyBeeQueue)
await app.ready()
await app.bq.create(TEST_QUEUE_NAME)
const expected = `Cannot override existing Queue at key: ${TEST_QUEUE_NAME}`
const error = await t.throwsAsync(app.bq.create(TEST_QUEUE_NAME))
t.is(error.message, expected)
})
test('"createProducer": Cannot override existing stored Queues in the queues decorator', async (t) => {
const app = require('fastify')()
app.register(fastifyBeeQueue)
await app.ready()
await app.bq.createProducer(TEST_QUEUE_NAME)
const expected = `Cannot override existing Queue at key: ${TEST_QUEUE_NAME}`
const error = await t.throwsAsync(app.bq.createProducer(TEST_QUEUE_NAME))
t.is(error.message, expected)
})