Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a new testing structure #13

Merged
merged 2 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions __tests__/authIsDisabled.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Create tests for authIsDisabled');
16 changes: 16 additions & 0 deletions __tests__/cleanAuthLevels.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const test = require('ava');
const mongoose = require('mongoose');
// const cleanAuthLevels = require('../src/cleanAuthLevels');

test.before((t) => {
t.context.schema = new mongoose.Schema({ friend: String });
});

test.todo('Schema passed in is not valid');
test.todo('Falsey authLevel value');
test.todo('Empty array authLevel value');
test.todo('Remove duplicate entries');
test.todo('Remove false entries');
test.todo('Remove entries that are not in the permissions object');
test.todo('authLevel with no issues');

3 changes: 3 additions & 0 deletions __tests__/embedPermissions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Migrate tests for embedPermissions');
3 changes: 3 additions & 0 deletions __tests__/getAuthorizedFields.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Migrate tests for getAuthorizedFields');
3 changes: 3 additions & 0 deletions __tests__/getUpdatePaths.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Migrate getUpdatePaths tests to this file');
3 changes: 3 additions & 0 deletions __tests__/hasPermission.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Migrate hasPermission tests here');
3 changes: 3 additions & 0 deletions __tests__/methods/Document.save.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Document.save');
3 changes: 3 additions & 0 deletions __tests__/methods/Document.update.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Document.update');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.aggreate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.aggregate. It should be a disabled method');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.bulkWrite.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.bulkWrite. It should be disabled, does not support middleware');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.count.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.count');
30 changes: 30 additions & 0 deletions __tests__/methods/Model.create.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const test = require('ava');
const mongoose = require('mongoose');
const authz = require('../../');
const IncompatibleMethodError = require('../../src/IncompatibleMethodError');

test.before(async () => {
await mongoose.connect('mongodb://localhost:27017/ModelCreateTests');
});

test('Model.create should not be callable with plugin installed', (t) => {
const schema = new mongoose.Schema({ friend: String });
schema.plugin(authz);
const MyModel = mongoose.model('ModelCreatePluggedIn', schema);

t.throws(
() => MyModel.create({ friend: 'bar' }),
IncompatibleMethodError,
);
});

test('Model.create should be callable without the plugin installed', async (t) => {
const schema = new mongoose.Schema({ friend: String });
const MyModel = mongoose.model('ModelCreateWithoutPluggin', schema);

await t.notThrows(MyModel.create({ friend: 'bar' }));
});

test.after.always(async () => {
await mongoose.disconnect();
});
3 changes: 3 additions & 0 deletions __tests__/methods/Model.deleteMany.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.deleteMany');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.deleteOne.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.deleteOne');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.distinct.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.distinct');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.find.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.find');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.findById.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.findById');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.findByIdAndDelete.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.findByIdAndDelete');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.findByIdAndRemove.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.findByIdAndRemove');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.findByIdAndUpdate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.findByIdAndUpdate');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.findOne.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.findOne');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.findOneAndDelete.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.findOneAndDelete');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.findOneAndRemove.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.findOneAndRemove');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.findOneAndUpdate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.findOneAndUpdate');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.geoSearch.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.geoSearch (probably disable)');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.increment.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.increment');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.isertMany.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.insertMany - disallow');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.mapReduce.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.mapReduce - disable');
30 changes: 30 additions & 0 deletions __tests__/methods/Model.remove.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const test = require('ava');
const mongoose = require('mongoose');
const authz = require('../../');
const IncompatibleMethodError = require('../../src/IncompatibleMethodError');

test.before(async () => {
await mongoose.connect('mongodb://localhost:27017/ModelRemoveTests');
});

test('Model.remove should not be callable with plugin installed', (t) => {
const schema = new mongoose.Schema({ friend: String });
schema.plugin(authz);
const MyModel = mongoose.model('ModelRemovePluggedIn', schema);

t.throws(
() => MyModel.remove({ friend: 'bar' }).exec(),
IncompatibleMethodError,
);
});

test('Model.remove should be callable without the plugin installed', async (t) => {
const schema = new mongoose.Schema({ friend: String });
const MyModel = mongoose.model('ModelRemoveWithoutPlugin', schema);

await t.notThrows(MyModel.remove({}).exec());
});

test.after.always(async () => {
await mongoose.disconnect();
});
3 changes: 3 additions & 0 deletions __tests__/methods/Model.replaceOne.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.replaceOne');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.update.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.update');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.updateMany.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.updateMany');
3 changes: 3 additions & 0 deletions __tests__/methods/Model.updateOne.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Write tests for Model.updateOne');
3 changes: 3 additions & 0 deletions __tests__/resolveAuthLevel.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Migrate resolveAuthLevel tests to here');
27 changes: 0 additions & 27 deletions __tests__/restrictedMethods.test.js

This file was deleted.

3 changes: 3 additions & 0 deletions __tests__/sanitizeDocumentList.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const test = require('ava');

test.todo('Migrate SanitizeDocumentList tests to this file');
19 changes: 8 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
const _ = require('lodash');
const {
resolveAuthLevel,
getAuthorizedFields,
hasPermission,
authIsDisabled,
sanitizeDocumentList,
getUpdatePaths,
} = require('./lib/helpers');

const PermissionDeniedError = require('./lib/PermissionDeniedError');
const IncompatibleMethodError = require('./lib/IncompatibleMethodError');
const getAuthorizedFields = require('./src/getAuthorizedFields');
const hasPermission = require('./src/hasPermission');
const authIsDisabled = require('./src/authIsDisabled');
const sanitizeDocumentList = require('./src/sanitizeDocumentList');
const getUpdatePaths = require('./src/getUpdatePaths');
const resolveAuthLevel = require('./src/resolveAuthLevel');
const PermissionDeniedError = require('./src/PermissionDeniedError');
const IncompatibleMethodError = require('./src/IncompatibleMethodError');

module.exports = (schema) => {
async function save(doc, options) {
Expand Down
Loading