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

Commit

Permalink
Expose #171
Browse files Browse the repository at this point in the history
  • Loading branch information
roschaefer committed Oct 9, 2018
1 parent 2f0508b commit e3ebd58
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions test/hooks/exclude-blacklisted.test.js
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' );
});
});
});
});
});

0 comments on commit e3ebd58

Please sign in to comment.