Skip to content
Open
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
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
node_modules
.meteor
package.js
.meteor
.npm
packages/
tests/
6,266 changes: 3,024 additions & 3,242 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
"lint": "eslint ."
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^8.2.1",
"@babel/core": "^7.26.0",
"@babel/eslint-parser": "^7.25.9",
"eslint": "^8.56.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.29.1"
},
"babel": {},
"eslintConfig": {
"extends": "airbnb-base",
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"env": {
"browser": true,
"jest": true
Expand Down
6 changes: 2 additions & 4 deletions package/deny/deny.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* global Collection2 */
// collection2 checks to make sure that simpl-schema package is added
import 'meteor/aldeed:collection2/dynamic';
import 'meteor/aldeed:collection2/static';
import SimpleSchema from 'meteor/aldeed:simple-schema';

Collection2.load();

// Extend the schema options allowed by SimpleSchema
SimpleSchema.extendOptions(['denyInsert', 'denyUpdate']);

Expand All @@ -21,7 +20,6 @@ Collection2.on('schema.attached', (collection, ss) => {
if (!this.isSet) return;

const def = this.definition;

if (def.denyInsert && this.isInsert) return 'insertNotAllowed';
if (def.denyUpdate && (this.isUpdate || this.isUpsert)) return 'updateNotAllowed';
});
Expand Down
4 changes: 2 additions & 2 deletions tests/.meteor/versions
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aldeed:[email protected].0
aldeed:[email protected].0
aldeed:[email protected].4
aldeed:[email protected].2
aldeed:[email protected]
[email protected]
[email protected]
Expand Down
127 changes: 92 additions & 35 deletions tests/deny.tests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import expect from 'expect';
import { expect } from 'chai';
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'meteor/aldeed:simple-schema';

Expand All @@ -17,52 +17,109 @@ test.attachSchema(new SimpleSchema({
}));

describe('deny', () => {
it('denyInsert', (done) => {
test.insert({
denyInsert: 'foo',
}, (error) => {
expect(error && error.message).toBe('Deny insert cannot be set during an insert in test insert');

describe('denyInsert', () => {
const evaluateInsert = ({ error, message }) => {
expect(error && error.message).to.equal(message);
const validationErrors = test.simpleSchema().namedContext().validationErrors();
expect(validationErrors.length).toBe(1);

expect(validationErrors.length).to.equal(1);
const key = validationErrors[0] || {};
expect(key.name).toBe('denyInsert');
expect(key.type).toBe('insertNotAllowed');
expect(key.name).to.equal('denyInsert');
expect(key.type).to.equal('insertNotAllowed');
};

done();
it('denies insert (async)', async () => {
try {
await test.insertAsync({ denyInsert: 'foo', })
} catch (error) {
evaluateInsert({ error, message: 'Deny insert cannot be set during an insert in test insertAsync' })
}
});

if (Meteor.isServer) {
it('denies insert (sync)', () => {
try {
test.insert({ denyInsert: 'foo', });
} catch (error) {
evaluateInsert({ error, message: 'Deny insert cannot be set during an insert in test insert' })
}
});
}
if (Meteor.isClient) {
it('denies insert (sync)', (done) => {
test.insert({ denyInsert: 'foo', }, error => {
evaluateInsert({ error, message: 'Deny insert cannot be set during an insert in test insert' })
done()
});
});
}
});

it('denyUpdate', (done) => {
test.insert({
denyUpdate: 'foo',
}, (err, newId) => {
expect(typeof newId).toBe('string');
describe('denyUpdate', () => {
const evaluateUpdate = ({ error, message }) => {
expect(error && error.message).to.equal(message);

const validationErrors = test.simpleSchema().namedContext().validationErrors();
expect(validationErrors.length).to.equal(1);

const key = validationErrors[0] || {};
expect(key.name).to.equal('denyUpdate');
expect(key.type).to.equal('updateNotAllowed');
}

it('denies update (async)', async () => {
const newId = await test.insertAsync({ denyUpdate: 'foo' });
try {
await test.updateAsync(newId, { $set: {
denyUpdate: 'foo',
},
})
} catch (error) {
evaluateUpdate({ error, message: 'Deny update cannot be set during an update in test updateAsync' })
}

test.update(newId, {
// valid use case
// Now test valid case
await test.updateAsync(newId, {
$set: {
denyUpdate: 'foo',
denyInsert: 'foo',
},
}, (error) => {
expect(error && error.message).toBe('Deny update cannot be set during an update in test update');
})
});

const validationErrors = test.simpleSchema().namedContext().validationErrors();
expect(validationErrors.length).toBe(1);
it('denyUpdate', (done) => {
test.insert({
denyUpdate: 'foo',
}, (err, newId) => {
expect(typeof newId).to.equal('string');

const key = validationErrors[0] || {};
expect(key.name).toBe('denyUpdate');
expect(key.type).toBe('updateNotAllowed');
try {
test.update(newId, {
$set: {
denyUpdate: 'foo',
},
}, (error) => {
expect(error && error.message).to.equal('Deny update cannot be set during an update in test update');

// Now test valid case
test.update(newId, {
$set: {
denyInsert: 'foo',
},
}, (e) => {
expect(!!e).toBe(false);
done();
});
const validationErrors = test.simpleSchema().namedContext().validationErrors();
expect(validationErrors.length).to.equal(1);

const key = validationErrors[0] || {};
expect(key.name).to.equal('denyUpdate');
expect(key.type).to.equal('updateNotAllowed');

// Now test valid case
test.update(newId, {
$set: {
denyInsert: 'foo',
},
}, (e) => {
expect(!!e).to.equal(false);
done();
});
});
} catch (error) {

}
});
});
});
Expand Down
Loading
Loading