Skip to content

Commit 1fcf85e

Browse files
authored
Merge pull request #12 from Meteor-Community-Packages/fix/dev-tools
fix(deps/tests): upgrade tests to support Meteor 2 + 3
2 parents afe3bbe + ac14a5d commit 1fcf85e

File tree

8 files changed

+3607
-5303
lines changed

8 files changed

+3607
-5303
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
node_modules
22
.meteor
33
package.js
4+
.meteor
5+
.npm
6+
packages/
7+
tests/

package-lock.json

Lines changed: 3024 additions & 3242 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
"lint": "eslint ."
66
},
77
"devDependencies": {
8-
"babel-cli": "^6.26.0",
9-
"babel-eslint": "^8.2.1",
8+
"@babel/core": "^7.26.0",
9+
"@babel/eslint-parser": "^7.25.9",
1010
"eslint": "^8.56.0",
1111
"eslint-config-airbnb-base": "^15.0.0",
1212
"eslint-plugin-import": "^2.29.1"
1313
},
14+
"babel": {},
1415
"eslintConfig": {
1516
"extends": "airbnb-base",
16-
"parser": "babel-eslint",
17+
"parser": "@babel/eslint-parser",
1718
"env": {
1819
"browser": true,
1920
"jest": true

package/deny/deny.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
/* global Collection2 */
12
// collection2 checks to make sure that simpl-schema package is added
2-
import 'meteor/aldeed:collection2/dynamic';
3+
import 'meteor/aldeed:collection2/static';
34
import SimpleSchema from 'meteor/aldeed:simple-schema';
45

5-
Collection2.load();
6-
76
// Extend the schema options allowed by SimpleSchema
87
SimpleSchema.extendOptions(['denyInsert', 'denyUpdate']);
98

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

2322
const def = this.definition;
24-
2523
if (def.denyInsert && this.isInsert) return 'insertNotAllowed';
2624
if (def.denyUpdate && (this.isUpdate || this.isUpsert)) return 'updateNotAllowed';
2725
});

tests/.meteor/versions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
aldeed:collection2@4.0.0
2-
aldeed:schema-deny@4.0.0
1+
aldeed:collection2@4.0.4
2+
aldeed:schema-deny@4.0.2
33
aldeed:simple-schema@1.13.1
44
allow-deny@1.1.1
55
autopublish@1.0.7

tests/deny.tests.js

Lines changed: 92 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import expect from 'expect';
1+
import { expect } from 'chai';
22
import { Mongo } from 'meteor/mongo';
33
import SimpleSchema from 'meteor/aldeed:simple-schema';
44

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

1919
describe('deny', () => {
20-
it('denyInsert', (done) => {
21-
test.insert({
22-
denyInsert: 'foo',
23-
}, (error) => {
24-
expect(error && error.message).toBe('Deny insert cannot be set during an insert in test insert');
25-
20+
describe('denyInsert', () => {
21+
const evaluateInsert = ({ error, message }) => {
22+
expect(error && error.message).to.equal(message);
2623
const validationErrors = test.simpleSchema().namedContext().validationErrors();
27-
expect(validationErrors.length).toBe(1);
28-
24+
expect(validationErrors.length).to.equal(1);
2925
const key = validationErrors[0] || {};
30-
expect(key.name).toBe('denyInsert');
31-
expect(key.type).toBe('insertNotAllowed');
26+
expect(key.name).to.equal('denyInsert');
27+
expect(key.type).to.equal('insertNotAllowed');
28+
};
3229

33-
done();
30+
it('denies insert (async)', async () => {
31+
try {
32+
await test.insertAsync({ denyInsert: 'foo', })
33+
} catch (error) {
34+
evaluateInsert({ error, message: 'Deny insert cannot be set during an insert in test insertAsync' })
35+
}
3436
});
37+
38+
if (Meteor.isServer) {
39+
it('denies insert (sync)', () => {
40+
try {
41+
test.insert({ denyInsert: 'foo', });
42+
} catch (error) {
43+
evaluateInsert({ error, message: 'Deny insert cannot be set during an insert in test insert' })
44+
}
45+
});
46+
}
47+
if (Meteor.isClient) {
48+
it('denies insert (sync)', (done) => {
49+
test.insert({ denyInsert: 'foo', }, error => {
50+
evaluateInsert({ error, message: 'Deny insert cannot be set during an insert in test insert' })
51+
done()
52+
});
53+
});
54+
}
3555
});
3656

37-
it('denyUpdate', (done) => {
38-
test.insert({
39-
denyUpdate: 'foo',
40-
}, (err, newId) => {
41-
expect(typeof newId).toBe('string');
57+
describe('denyUpdate', () => {
58+
const evaluateUpdate = ({ error, message }) => {
59+
expect(error && error.message).to.equal(message);
60+
61+
const validationErrors = test.simpleSchema().namedContext().validationErrors();
62+
expect(validationErrors.length).to.equal(1);
63+
64+
const key = validationErrors[0] || {};
65+
expect(key.name).to.equal('denyUpdate');
66+
expect(key.type).to.equal('updateNotAllowed');
67+
}
68+
69+
it('denies update (async)', async () => {
70+
const newId = await test.insertAsync({ denyUpdate: 'foo' });
71+
try {
72+
await test.updateAsync(newId, { $set: {
73+
denyUpdate: 'foo',
74+
},
75+
})
76+
} catch (error) {
77+
evaluateUpdate({ error, message: 'Deny update cannot be set during an update in test updateAsync' })
78+
}
4279

43-
test.update(newId, {
80+
// valid use case
81+
// Now test valid case
82+
await test.updateAsync(newId, {
4483
$set: {
45-
denyUpdate: 'foo',
84+
denyInsert: 'foo',
4685
},
47-
}, (error) => {
48-
expect(error && error.message).toBe('Deny update cannot be set during an update in test update');
86+
})
87+
});
4988

50-
const validationErrors = test.simpleSchema().namedContext().validationErrors();
51-
expect(validationErrors.length).toBe(1);
89+
it('denyUpdate', (done) => {
90+
test.insert({
91+
denyUpdate: 'foo',
92+
}, (err, newId) => {
93+
expect(typeof newId).to.equal('string');
5294

53-
const key = validationErrors[0] || {};
54-
expect(key.name).toBe('denyUpdate');
55-
expect(key.type).toBe('updateNotAllowed');
95+
try {
96+
test.update(newId, {
97+
$set: {
98+
denyUpdate: 'foo',
99+
},
100+
}, (error) => {
101+
expect(error && error.message).to.equal('Deny update cannot be set during an update in test update');
56102

57-
// Now test valid case
58-
test.update(newId, {
59-
$set: {
60-
denyInsert: 'foo',
61-
},
62-
}, (e) => {
63-
expect(!!e).toBe(false);
64-
done();
65-
});
103+
const validationErrors = test.simpleSchema().namedContext().validationErrors();
104+
expect(validationErrors.length).to.equal(1);
105+
106+
const key = validationErrors[0] || {};
107+
expect(key.name).to.equal('denyUpdate');
108+
expect(key.type).to.equal('updateNotAllowed');
109+
110+
// Now test valid case
111+
test.update(newId, {
112+
$set: {
113+
denyInsert: 'foo',
114+
},
115+
}, (e) => {
116+
expect(!!e).to.equal(false);
117+
done();
118+
});
119+
});
120+
} catch (error) {
121+
122+
}
66123
});
67124
});
68125
});

0 commit comments

Comments
 (0)