1- import expect from 'expect ' ;
1+ import { expect } from 'chai ' ;
22import { Mongo } from 'meteor/mongo' ;
33import SimpleSchema from 'meteor/aldeed:simple-schema' ;
44
@@ -17,52 +17,109 @@ test.attachSchema(new SimpleSchema({
1717} ) ) ;
1818
1919describe ( '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