Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit e3ebd58

Browse files
committed
Expose #171
1 parent 2f0508b commit e3ebd58

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const assert = require('assert');
2+
const feathers = require('@feathersjs/feathers');
3+
const excludeBlacklisted = require('../../server/hooks/exclude-blacklisted');
4+
5+
let app;
6+
let usersettings = {};
7+
beforeEach(() => {
8+
// Create a new plain Feathers application
9+
app = feathers();
10+
11+
// Register a dummy custom service that just return the
12+
// message data back
13+
app.use('/usersettings', {
14+
async find() {
15+
return {
16+
data: [usersettings]
17+
};
18+
}
19+
});
20+
});
21+
22+
describe('\'exclude-blacklisted\' hook', () => {
23+
context('given a blacklist', () => {
24+
let mock;
25+
beforeEach(() => {
26+
usersettings = { blacklist: ['4711'] };
27+
mock = {
28+
type: 'before',
29+
method: 'find',
30+
params: {
31+
user: { _id: 'whatever' }
32+
},
33+
app
34+
};
35+
});
36+
37+
context('query param `userId` is an object', () => {
38+
it('adds one key', () => {
39+
mock.params.query = {
40+
userId: { $ne: 'user id' }
41+
};
42+
43+
const hook = excludeBlacklisted();
44+
return hook(mock).then(result => {
45+
assert.deepEqual(result.params.query.userId, {
46+
$ne: 'user id',
47+
$nin: ['4711']
48+
});
49+
});
50+
});
51+
});
52+
53+
context('query param `userId` is set to an exact id', () => {
54+
it('has no effect', () => {
55+
mock.params.query = {
56+
userId: 'exact user id'
57+
};
58+
59+
const hook = excludeBlacklisted();
60+
return hook(mock).then(result => {
61+
assert.deepEqual(result.params.query.userId, 'exact user id' );
62+
});
63+
});
64+
});
65+
});
66+
});

0 commit comments

Comments
 (0)