Skip to content

Commit 6cffb99

Browse files
committed
Updated test
1 parent ebf90eb commit 6cffb99

File tree

1 file changed

+14
-42
lines changed

1 file changed

+14
-42
lines changed

test.js

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,23 @@ t.beforeEach(done => {
1010

1111
fastify.register(fastifyRedis, {
1212
host: '127.0.0.1'
13-
}, (err) => {
14-
t.error(err)
1513
})
1614

1715
fastify.ready(err => {
1816
t.error(err)
1917

20-
fastify.redis.flushdb(() => {
18+
fastify.redis.flushall(() => {
2119
fastify.close()
2220
done()
2321
})
2422
})
2523
})
2624

2725
test('fastify.redis should exist', t => {
28-
t.plan(3)
26+
t.plan(2)
2927
const fastify = Fastify()
3028
fastify.register(fastifyRedis, {
3129
host: '127.0.0.1'
32-
}, (err) => {
33-
t.error(err)
3430
})
3531

3632
fastify.ready(err => {
@@ -42,13 +38,11 @@ test('fastify.redis should exist', t => {
4238
})
4339

4440
test('fastify.redis should be the redis client', t => {
45-
t.plan(5)
41+
t.plan(4)
4642
const fastify = Fastify()
4743

4844
fastify.register(fastifyRedis, {
4945
host: '127.0.0.1'
50-
}, (err) => {
51-
t.error(err)
5246
})
5347

5448
fastify.ready(err => {
@@ -66,57 +60,35 @@ test('fastify.redis should be the redis client', t => {
6660
})
6761
})
6862

69-
test('fastify.redis should exist when use the custom redis driver', t => {
70-
t.plan(3)
71-
const fastify = Fastify()
72-
73-
fastify.register(fastifyRedis, {
74-
driver: require('ioredis'),
75-
host: '127.0.0.1'
76-
}, (err) => {
77-
t.error(err)
78-
})
79-
80-
fastify.ready(err => {
81-
t.error(err)
82-
t.ok(fastify.redis)
83-
84-
fastify.close()
85-
})
86-
})
87-
88-
test('fastify.redis should be the redis client when use the custom redis driver', t => {
89-
t.plan(5)
63+
test('promises support', t => {
64+
t.plan(2)
9065
const fastify = Fastify()
9166

9267
fastify.register(fastifyRedis, {
93-
driver: require('ioredis'),
9468
host: '127.0.0.1'
95-
}, (err) => {
96-
t.error(err)
9769
})
9870

9971
fastify.ready(err => {
10072
t.error(err)
10173

102-
fastify.redis.set('key', 'value', err => {
103-
t.error(err)
104-
fastify.redis.get('key', (err, val) => {
105-
t.error(err)
74+
fastify.redis.set('key', 'value')
75+
.then(() => {
76+
return fastify.redis.get('key')
77+
})
78+
.then(val => {
10679
t.equal(val, 'value')
107-
10880
fastify.close()
10981
})
110-
})
82+
.catch(err => t.fail(err))
11183
})
11284
})
11385

114-
test('fastify.redis should be a singleton', t => {
86+
test('custom client', t => {
11587
t.plan(5)
11688
const fastify = Fastify()
117-
const redis = require('redis').createClient({host: 'localhost', port: 6379})
89+
const redis = require('redis').createClient({ host: 'localhost', port: 6379 })
11890

119-
fastify.register(fastifyRedis, {client: redis})
91+
fastify.register(fastifyRedis, { client: redis })
12092

12193
fastify.ready(err => {
12294
t.error(err)

0 commit comments

Comments
 (0)