This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f0508b
commit e3ebd58
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const assert = require('assert'); | ||
const feathers = require('@feathersjs/feathers'); | ||
const excludeBlacklisted = require('../../server/hooks/exclude-blacklisted'); | ||
|
||
let app; | ||
let usersettings = {}; | ||
beforeEach(() => { | ||
// Create a new plain Feathers application | ||
app = feathers(); | ||
|
||
// Register a dummy custom service that just return the | ||
// message data back | ||
app.use('/usersettings', { | ||
async find() { | ||
return { | ||
data: [usersettings] | ||
}; | ||
} | ||
}); | ||
}); | ||
|
||
describe('\'exclude-blacklisted\' hook', () => { | ||
context('given a blacklist', () => { | ||
let mock; | ||
beforeEach(() => { | ||
usersettings = { blacklist: ['4711'] }; | ||
mock = { | ||
type: 'before', | ||
method: 'find', | ||
params: { | ||
user: { _id: 'whatever' } | ||
}, | ||
app | ||
}; | ||
}); | ||
|
||
context('query param `userId` is an object', () => { | ||
it('adds one key', () => { | ||
mock.params.query = { | ||
userId: { $ne: 'user id' } | ||
}; | ||
|
||
const hook = excludeBlacklisted(); | ||
return hook(mock).then(result => { | ||
assert.deepEqual(result.params.query.userId, { | ||
$ne: 'user id', | ||
$nin: ['4711'] | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
context('query param `userId` is set to an exact id', () => { | ||
it('has no effect', () => { | ||
mock.params.query = { | ||
userId: 'exact user id' | ||
}; | ||
|
||
const hook = excludeBlacklisted(); | ||
return hook(mock).then(result => { | ||
assert.deepEqual(result.params.query.userId, 'exact user id' ); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |