forked from 352Media/mongoose-authorization
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating a new testing structure (#13)
* Creating a new testing structure This diff does a couple things: - It creates test file for every Model and Document method that we'll need to handle and test. These can be gradually filled in. - It breaks helpers.js functions into separate files. Each one of those now has a corresponding test file. In upcoming diffs, I'll move the existing tests into this new structure. * fixing lint issue
- Loading branch information
Showing
50 changed files
with
370 additions
and
215 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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Create tests for authIsDisabled'); |
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,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'); | ||
|
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Migrate tests for embedPermissions'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Migrate tests for getAuthorizedFields'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Migrate getUpdatePaths tests to this file'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Migrate hasPermission tests here'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Document.save'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Document.update'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.aggregate. It should be a disabled method'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.bulkWrite. It should be disabled, does not support middleware'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.count'); |
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,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(); | ||
}); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.deleteMany'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.deleteOne'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.distinct'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.find'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.findById'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.findByIdAndDelete'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.findByIdAndRemove'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.findByIdAndUpdate'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.findOne'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.findOneAndDelete'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.findOneAndRemove'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.findOneAndUpdate'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.geoSearch (probably disable)'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.increment'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.insertMany - disallow'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.mapReduce - disable'); |
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,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(); | ||
}); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.replaceOne'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.update'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.updateMany'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Write tests for Model.updateOne'); |
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Migrate resolveAuthLevel tests to here'); |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
const test = require('ava'); | ||
|
||
test.todo('Migrate SanitizeDocumentList tests to this file'); |
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
Oops, something went wrong.