Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit 0bccef4

Browse files
committed
Added test for the redisClient, reorganised folders
1 parent 7fdb054 commit 0bccef4

File tree

8 files changed

+58
-12
lines changed

8 files changed

+58
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"build": "webpack --env build --mode production",
4242
"dev": "webpack --progress --colors --watch --env dev --mode development",
4343
"dev-travis": "webpack --mode production && npm run test",
44-
"mocha": "mocha --require babel-core/register --colors ./test/*.test.js --exit",
44+
"mocha": "mocha --require babel-core/register --colors ./test/ --recursive --exit",
4545
"reporter": "NODE_ENV=test nyc npm run mocha",
4646
"test": "npm run reporter",
4747
"test:redis-after": "NODE_ENV=test nyc mocha --require babel-core/register --colors ./test/redis-after.test.js --watch",

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { removeCacheInformation as hookRemoveCacheInformation } from './hooks/ca
55
import { before as redisBeforeHook} from './hooks/redis';
66
import { after as redisAfterHook} from './hooks/redis';
77

8-
export {
8+
export default {
99
redisClient,
1010
cacheRoutes,
1111
hookCache,

src/redisClient.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import redis from 'redis';
22

33
export default function redisClient() { // eslint-disable-line no-unused-vars
44
this.set('redisClient', redis.createClient(this.get('redis')));
5+
return this;
56
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
22
import redis from 'redis';
3-
import { redisAfterHook as a } from '../src';
3+
import { redisAfterHook as a } from '../../src';
44
// import moment from 'moment';
55

66
const client = redis.createClient();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22
import redis from 'redis';
33
import moment from 'moment';
4-
import { redisBeforeHook as b, redisAfterHook as a } from '../src';
4+
import { redisBeforeHook as b, redisAfterHook as a } from '../../src';
55

66
const client = redis.createClient();
77

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22
import redis from 'redis';
33
import moment from 'moment';
4-
import { hookRemoveCacheInformation as r } from '../src';
4+
import { hookRemoveCacheInformation as r } from '../../src';
55

66
const client = redis.createClient();
77

test/index.test.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
import { expect } from 'chai';
2-
import { redisClient, cacheRoutes, redisAfterHook, redisBeforeHook, hookRemoveCacheInformation } from '../src';
2+
import * as lib from '../src';
33

44
describe('feathers-hooks-rediscache', () => {
55
it('loads Redis Client', () => {
6-
expect(typeof redisClient).to.equal('function', 'It worked');
6+
expect(lib).to.respondTo('redisClient');
77
});
8+
89
it('loads routes', () => {
9-
expect(typeof cacheRoutes).to.equal('function', 'It worked');
10+
expect(lib).to.respondTo('cacheRoutes');
1011
});
12+
1113
it('loads the after Redis Cache hook', () => {
12-
expect(typeof redisAfterHook).to.equal('function', 'It worked');
14+
expect(lib).to.respondTo('redisAfterHook');
1315
});
16+
1417
it('loads the before Redis Cache hook', () => {
15-
expect(typeof redisBeforeHook).to.equal('function', 'It worked');
18+
expect(lib).to.respondTo('redisBeforeHook');
1619
});
20+
1721
it('loads the remove Redis Cache Object hook', () => {
18-
expect(typeof hookRemoveCacheInformation).to.equal('function', 'It worked');
22+
expect(lib).to.respondTo('hookRemoveCacheInformation');
1923
});
24+
2025
it('loads the cache hook', () => {
21-
expect(typeof redisBeforeHook).to.equal('function', 'It worked');
26+
expect(lib).to.respondTo('hookCache');
2227
});
2328
});

test/run-last/redis-client.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { expect } from 'chai';
2+
import { redisClient } from '../../src';
3+
4+
describe('Redis Before Hook', () => {
5+
6+
it('It loads and responds', () => {
7+
expect(typeof redisClient).to.equal('function');
8+
});
9+
10+
it('Loads the client with custom settings', () => {
11+
const c = redisClient.bind({
12+
set: function (key, value) {
13+
this[key] = value;
14+
},
15+
get: function (key) {
16+
return {
17+
host: 'my-redis-service.example.com',
18+
port: 1234
19+
};
20+
}
21+
});
22+
const result = c();
23+
24+
expect(result.redisClient.address).to.equal('my-redis-service.example.com:1234');
25+
});
26+
27+
it('Loads the client with defaults', () => {
28+
const c = redisClient.bind({
29+
set: function (key, value) {
30+
this[key] = value;
31+
},
32+
get: function (key) {
33+
return null;
34+
}
35+
});
36+
const result = c();
37+
38+
expect(result.redisClient.address).to.equal('127.0.0.1:6379');
39+
});
40+
});

0 commit comments

Comments
 (0)