@@ -26,10 +26,11 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
26
26
const un = new Unmarshaller ( ) ;
27
27
28
28
// act and assert
29
- return un . unmarshall ( payload )
30
- . then ( ( ) => { throw new Error ( "failed" ) ; } )
31
- . catch ( ( err ) =>
32
- expect ( err . message ) . to . equal ( "payload is null or undefined" ) ) ;
29
+ try {
30
+ un . unmarshall ( payload ) ;
31
+ } catch ( err ) {
32
+ expect ( err . message ) . to . equal ( "payload is null or undefined" ) ;
33
+ }
33
34
} ) ;
34
35
35
36
it ( "Throw error when headers is null" , ( ) => {
@@ -39,10 +40,11 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
39
40
const un = new Unmarshaller ( ) ;
40
41
41
42
// act and assert
42
- return un . unmarshall ( payload , headers )
43
- . then ( ( ) => { throw new Error ( "failed" ) ; } )
44
- . catch ( ( err ) =>
45
- expect ( err . message ) . to . equal ( "headers is null or undefined" ) ) ;
43
+ try {
44
+ un . unmarshall ( payload , headers ) ;
45
+ } catch ( err ) {
46
+ expect ( err . message ) . to . equal ( "headers is null or undefined" ) ;
47
+ }
46
48
} ) ;
47
49
48
50
it ( "Throw error when there is no content-type header" , ( ) => {
@@ -52,10 +54,11 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
52
54
const un = new Unmarshaller ( ) ;
53
55
54
56
// act and assert
55
- un . unmarshall ( payload , headers )
56
- . then ( ( ) => { throw new Error ( "failed" ) ; } )
57
- . catch ( ( err ) =>
58
- expect ( err . message ) . to . equal ( "content-type header not found" ) ) ;
57
+ try {
58
+ un . unmarshall ( payload , headers ) ;
59
+ } catch ( err ) {
60
+ expect ( err . message ) . to . equal ( "content-type header not found" ) ;
61
+ }
59
62
} ) ;
60
63
61
64
it ( "Throw error when content-type is not allowed" , ( ) => {
@@ -67,10 +70,11 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
67
70
const un = new Unmarshaller ( ) ;
68
71
69
72
// act and assert
70
- un . unmarshall ( payload , headers )
71
- . then ( ( ) => { throw new Error ( "failed" ) ; } )
72
- . catch ( ( err ) =>
73
- expect ( err . message ) . to . equal ( "content type not allowed" ) ) ;
73
+ try {
74
+ un . unmarshall ( payload , headers ) ;
75
+ } catch ( err ) {
76
+ expect ( err . message ) . to . equal ( "content type not allowed" ) ;
77
+ }
74
78
} ) ;
75
79
76
80
describe ( "Structured" , ( ) => {
@@ -83,10 +87,11 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
83
87
const un = new Unmarshaller ( ) ;
84
88
85
89
// act and assert
86
- un . unmarshall ( payload , headers )
87
- . then ( ( ) => { throw new Error ( "failed" ) ; } )
88
- . catch ( ( err ) =>
89
- expect ( err . message ) . to . equal ( "structured+type not allowed" ) ) ;
90
+ try {
91
+ un . unmarshall ( payload , headers ) ;
92
+ } catch ( err ) {
93
+ expect ( err . message ) . to . equal ( "structured+type not allowed" ) ;
94
+ }
90
95
} ) ;
91
96
92
97
it ( "Throw error when the event does not follow the spec 0.3" , ( ) => {
@@ -108,10 +113,11 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
108
113
const un = new Unmarshaller ( ) ;
109
114
110
115
// act and assert
111
- un . unmarshall ( payload , headers )
112
- . then ( ( ) => { throw new Error ( "failed" ) ; } )
113
- . catch ( ( err ) =>
114
- expect ( err . message ) . to . equal ( "invalid payload" ) ) ;
116
+ try {
117
+ un . unmarshall ( payload , headers ) ;
118
+ } catch ( err ) {
119
+ expect ( err . message ) . to . equal ( "invalid payload" ) ;
120
+ }
115
121
} ) ;
116
122
117
123
it ( "Should accept event that follow the spec 0.3" , ( ) => {
@@ -134,13 +140,8 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
134
140
const un = new Unmarshaller ( ) ;
135
141
136
142
// act and assert
137
- return un . unmarshall ( payload , headers )
138
- . then ( ( actual ) =>
139
- expect ( actual ) . to . be . an ( "object" ) )
140
- . catch ( ( err ) => {
141
- console . error ( err ) ;
142
- throw err ;
143
- } ) ;
143
+ const event = un . unmarshall ( payload , headers ) ;
144
+ expect ( event instanceof CloudEvent ) . to . equal ( true ) ;
144
145
} ) ;
145
146
146
147
it ( "Should parse 'data' stringfied json to json object" , ( ) => {
@@ -163,14 +164,8 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
163
164
const un = new Unmarshaller ( ) ;
164
165
165
166
// act and assert
166
- return un . unmarshall ( payload , headers )
167
- . then ( ( actual ) => {
168
- expect ( actual . getData ( ) ) . to . deep . equal ( data ) ;
169
- } )
170
- . catch ( ( err ) => {
171
- console . error ( err ) ;
172
- throw err ;
173
- } ) ;
167
+ const event = un . unmarshall ( payload , headers ) ;
168
+ expect ( event . getData ( ) ) . to . deep . equal ( data ) ;
174
169
} ) ;
175
170
} ) ;
176
171
@@ -193,10 +188,11 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
193
188
const un = new Unmarshaller ( ) ;
194
189
195
190
// act and assert
196
- un . unmarshall ( payload , attributes )
197
- . then ( ( ) => { throw new Error ( "failed" ) ; } )
198
- . catch ( ( err ) =>
199
- expect ( err . message ) . to . equal ( "content type not allowed" ) ) ;
191
+ try {
192
+ un . unmarshall ( payload , attributes ) ;
193
+ } catch ( err ) {
194
+ expect ( err . message ) . to . equal ( "content type not allowed" ) ;
195
+ }
200
196
} ) ;
201
197
202
198
it ( "Throw error when the event does not follow the spec 0.3" , ( ) => {
@@ -217,10 +213,11 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
217
213
const un = new Unmarshaller ( ) ;
218
214
219
215
// act and assert
220
- un . unmarshall ( payload , attributes )
221
- . then ( ( ) => { throw new Error ( "failed" ) ; } )
222
- . catch ( ( err ) =>
223
- expect ( err . message ) . to . not . empty ) ;
216
+ try {
217
+ un . unmarshall ( payload , attributes ) ;
218
+ } catch ( err ) {
219
+ expect ( err . message ) . to . equal ( "header 'ce-specversion' not found" ) ;
220
+ }
224
221
} ) ;
225
222
226
223
it ( "No error when all attributes are in place" , ( ) => {
@@ -241,8 +238,8 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
241
238
const un = new Unmarshaller ( ) ;
242
239
243
240
// act and assert
244
- un . unmarshall ( payload , attributes )
245
- . then ( ( actual ) => expect ( actual ) . to . be . an ( "object" ) ) ;
241
+ const event = un . unmarshall ( payload , attributes ) ;
242
+ expect ( event instanceof CloudEvent ) . to . equal ( true ) ;
246
243
} ) ;
247
244
248
245
it ( "Throw error when 'ce-datacontentencoding' is not allowed" , ( ) => {
@@ -263,11 +260,11 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
263
260
const un = new Unmarshaller ( ) ;
264
261
265
262
// act and assert
266
- return un . unmarshall ( payload , attributes )
267
- . then ( ( ) => { throw new Error ( "failed" ) ; } )
268
- . catch ( ( err ) => {
269
- expect ( err . message ) . to . equal ( "unsupported datacontentencoding" ) ;
270
- } ) ;
263
+ try {
264
+ un . unmarshall ( payload , attributes ) ;
265
+ } catch ( err ) {
266
+ expect ( err . message ) . to . equal ( "unsupported datacontentencoding" ) ;
267
+ }
271
268
} ) ;
272
269
273
270
it ( "No error when 'ce-datacontentencoding' is base64" , ( ) => {
@@ -291,12 +288,8 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
291
288
const un = new Unmarshaller ( ) ;
292
289
293
290
// act and assert
294
- return un . unmarshall ( payload , attributes )
295
- . then ( ( actual ) => expect ( actual . getData ( ) ) . to . deep . equal ( expected ) )
296
- . catch ( ( err ) => {
297
- console . error ( err ) ;
298
- throw err ;
299
- } ) ;
291
+ const event = un . unmarshall ( payload , attributes ) ;
292
+ expect ( event . getData ( ) ) . to . deep . equal ( expected ) ;
300
293
} ) ;
301
294
} ) ;
302
295
} ) ;
0 commit comments