-
Notifications
You must be signed in to change notification settings - Fork 4
/
integration.tests.js
130 lines (126 loc) · 5.99 KB
/
integration.tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import SecurityException from './lib/SecurityException';
import { Serrurier, server, cadenas } from './lib/main';
import { ValidationError } from 'meteor/mdg:validation-error';
import {
decorateDescription,
ActionsStore,
Logger,
registerIsolatedReporter
} from 'meteor/svein:serrurier-core';
import { decoratorMock, once } from 'meteor/svein:serrurier-core/lib/utils';
import { chai } from 'meteor/practicalmeteor:chai';
const expect = chai.expect;
Logger.silence();
describe( 'svein:serrurier-core with svein:serrurier', function() {
let securityContext = { reason:'', exceptionId:'any-kind-of-error' };
describe( 'when the `decorateDescription` function is applied to an Astro description `object`', function() {
let description1,
description2,
onceBefore = once( function(){
registerIsolatedReporter( SecurityException, function() {
console.info('SecurityException reporter is being called.');
});
description1 = decorateDescription({
name: 'MyAstroClass1',
events: {
eventA: function() {
throw new SecurityException( securityContext );
}
},
methods: {
methodA: function() {
throw new SecurityException( securityContext );
}
}
});
description2 = decorateDescription({
name: 'MyAstroClass2',
events: {
eventA: [
function() { throw new Error();},
function() {}
]
},
methods: {
methodA: function() {
throw new Error();
}
}
});
});
before( onceBefore );
describe( 'any wrapped method called `methodName` when a reporter listen to `SecurityException`', function() {
it( 'should have the "isSecured" property set in the store', function() {
expect( ActionsStore.getProp( description1.methods.methodA, 'isSecured' ) ).to.be.true;
});
it( 'should have the "descriptor" property set to `${description.name}#${methodName}` available in the store', function() {
expect( ActionsStore.getProp( description1.methods.methodA, 'descriptor' )).to.equal( 'MyAstroClass1#methodA' );
});
});
describe( 'any first wrapped event listener called `listenerdName`', function() {
it( 'should have the "isSecured" property set in the store', function() {
expect( ActionsStore.getProp( description1.events.eventA[0], 'isSecured' ) ).to.be.true;
});
it( 'should have the "descriptor" property set to `${description.name}#${listenerdName}` available in the store', function() {
expect( ActionsStore.getProp( description1.events.eventA[0], 'descriptor' )).to.equal( 'MyAstroClass1#eventA' );
});
});
describe( 'any second wrapped event listener called `listenerName`', function() {
it( 'should have the "descriptor" property set to `${description.name}#${listenerdName}1` available in the store', function() {
expect( ActionsStore.getProp( description2.events.eventA[1], 'descriptor' )).to.equal( 'MyAstroClass2#eventA1' );
});
});
describe( 'a `description.methods` wrapped field member that threw a `SecurityException`', function() {
it( 'should not anymore throw an instance of `SecurityException`', function() {
expect( function() { description1.methods.methodA(); }).not.to.throw( SecurityException );
});
});
describe( 'a `description.events` wrapped field member that threw a `SecurityException`', function() {
it( 'should not anymore throw an instance of `SecurityException` ', function() {
expect( function() { description1.events.eventA[0](); }).not.to.throw( SecurityException );
});
});
describe( 'a `description.methods` wrapped field member that threw any but a `SecurityException`', function() {
it( 'should still throw this error', function() {
expect( function() { description2.methods.methodA(); }).to.throw( Error );
});
});
describe( 'a `description.events` wrapped field member that threw any but a `SecurityException`', function() {
it( 'should still throw this error`', function() {
expect( function() { description2.events.eventA[0](); }).to.throw( Error );
});
});
});
});
describe( 'svein:serrurier with mdg:validation-error', function() {
describe( 'calling a server decorated method throwing a ValidationError', function() {
let MyClass;
const onceBefore = once( function() {
function thrower(){
throw new ValidationError([
{
name: 'cost',
type: 'out-of-range',
value: 1456,
min: 0,
max: 100
}
]);
}
const description = {
name: 'AClassThatShouldGoAlongWithValidationError',
methods: {
methodA: thrower
}
};
decoratorMock( description.methods, 'methodA', server());
MyClass = Serrurier.createClass( description );
});
before( onceBefore );
it( 'should be passed to the given callback', function() {
(new MyClass).methodA( function( err ) {
expect(ValidationError.is(err)).to.be.true ;
});
});
});
});