* Use [node-]redis as a direct dependency * Extract Redis client creation to its own module * Attach extensive logging in the Redis client creation module * Allow the rate limiter to pass requests when Redis is disconnected * Update rate-limit-redis * Default error input to empty object for formatRedisError method * Provide a name for the rate limiter's Redis client * Include redis-mock, exclude ioredis/ioredis-mock * Remove unused RedisAccessor#exists method * Switch RedisAccessor to use redis/redis-mock * Provide a name for logging on the Redis page cache * Remove extraneous trailing space from Redis logging prefix Our updated use of console.* will already be adding a space after the prefix * Replace ioredis-mock with redis-mock in tests * Revert removal of ioredis dependency * Bind Redis client to async promisified methods * Extract former RedisAccessor constructor tests to new create-client tests * Update RedisAccessor tests to work with the callback-based redis client * Handle formatting Redis errors (or not) with more resiliency
34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
const createRedisClient = require('../../../lib/redis/create-client')
|
|
|
|
const redisUrl = 'http://localhost:6379'
|
|
|
|
describe('create-client', () => {
|
|
test('returns null if no URL is provided', async () => {
|
|
expect(createRedisClient({})).toBe(null)
|
|
})
|
|
|
|
test('throws if database number is provided but is not a number', async () => {
|
|
expect(() => createRedisClient({ url: redisUrl, db: 'dbName' })).toThrowError(
|
|
new TypeError('Redis database number must be an integer between 0 and 15 but was: "dbName"')
|
|
)
|
|
})
|
|
|
|
test('throws if database number is provided but is not an integer', async () => {
|
|
expect(() => createRedisClient({ url: redisUrl, db: 1.5 })).toThrowError(
|
|
new TypeError('Redis database number must be an integer between 0 and 15 but was: 1.5')
|
|
)
|
|
})
|
|
|
|
test('throws if database number is provided but is less than 0', async () => {
|
|
expect(() => createRedisClient({ url: redisUrl, db: -1 })).toThrowError(
|
|
new TypeError('Redis database number must be an integer between 0 and 15 but was: -1')
|
|
)
|
|
})
|
|
|
|
test('throws if database number is provided but is greater than max allowed', async () => {
|
|
expect(() => createRedisClient({ url: redisUrl, db: 16 })).toThrowError(
|
|
new TypeError('Redis database number must be an integer between 0 and 15 but was: 16')
|
|
)
|
|
})
|
|
})
|