@@ -61,10 +61,6 @@ describe("CloudEvents Spec v1.0", () => {
61
61
it ( "Should have 'time'" , ( ) => {
62
62
expect ( cloudevent . getTime ( ) ) . to . equal ( time . toISOString ( ) ) ;
63
63
} ) ;
64
-
65
- it ( "Should have 'data'" , ( ) => {
66
- expect ( cloudevent . getData ( ) ) . to . deep . equal ( data ) ;
67
- } ) ;
68
64
} ) ;
69
65
70
66
describe ( "Extenstions Constraints" , ( ) => {
@@ -86,8 +82,8 @@ describe("CloudEvents Spec v1.0", () => {
86
82
. to . equal ( "an-string" ) ;
87
83
} ) ;
88
84
89
- it ( "should be ok when type is 'ArrayBuffer ' for 'Binary'" , ( ) => {
90
- let myBinary = new ArrayBuffer ( 2019 ) ;
85
+ it ( "should be ok when type is 'Uint32Array ' for 'Binary'" , ( ) => {
86
+ let myBinary = new Uint32Array ( 2019 ) ;
91
87
cloudevent . addExtension ( "ext-binary" , myBinary ) ;
92
88
expect ( cloudevent . spec . payload [ "ext-binary" ] )
93
89
. to . equal ( myBinary ) ;
@@ -189,24 +185,6 @@ describe("CloudEvents Spec v1.0", () => {
189
185
} ) ;
190
186
} ) ;
191
187
192
- describe ( "'data'" , ( ) => {
193
- it ( "should maintain the type of data when no data content type" , ( ) => {
194
- delete cloudevent . spec . payload . datacontenttype ;
195
- cloudevent
196
- . data ( JSON . stringify ( data ) ) ;
197
-
198
- expect ( typeof cloudevent . getData ( ) ) . to . equal ( "string" ) ;
199
- cloudevent . dataContentType ( dataContentType ) ;
200
- } ) ;
201
-
202
- it ( "should convert data with stringified json to a json object" , ( ) => {
203
- cloudevent
204
- . dataContentType ( dataContentType )
205
- . data ( JSON . stringify ( data ) ) ;
206
- expect ( cloudevent . getData ( ) ) . to . deep . equal ( data ) ;
207
- } ) ;
208
- } ) ;
209
-
210
188
describe ( "'subject'" , ( ) => {
211
189
it ( "should throw an error when is an empty string" , ( ) => {
212
190
cloudevent . subject ( "" ) ;
@@ -224,4 +202,40 @@ describe("CloudEvents Spec v1.0", () => {
224
202
} ) ;
225
203
} ) ;
226
204
} ) ;
205
+
206
+ describe ( "Event data constraints" , ( ) => {
207
+ it ( "Should have 'data'" , ( ) => {
208
+ expect ( cloudevent . getData ( ) ) . to . deep . equal ( data ) ;
209
+ } ) ;
210
+
211
+ it ( "should maintain the type of data when no data content type" , ( ) => {
212
+ delete cloudevent . spec . payload . datacontenttype ;
213
+ cloudevent
214
+ . data ( JSON . stringify ( data ) ) ;
215
+
216
+ expect ( typeof cloudevent . getData ( ) ) . to . equal ( "string" ) ;
217
+ cloudevent . dataContentType ( dataContentType ) ;
218
+ } ) ;
219
+
220
+ it ( "should convert data with stringified json to a json object" , ( ) => {
221
+ cloudevent
222
+ . dataContentType ( dataContentType )
223
+ . data ( JSON . stringify ( data ) ) ;
224
+ expect ( cloudevent . getData ( ) ) . to . deep . equal ( data ) ;
225
+ } ) ;
226
+
227
+ it ( "should be ok when type is 'Uint32Array' for 'Binary'" , ( ) => {
228
+ let dataString = ")(*~^my data for ce#@#$%"
229
+
230
+ let expected = Uint32Array . from ( dataString , ( c ) => c . codePointAt ( 0 ) ) ; ;
231
+ let olddct = cloudevent . getDataContentType ( ) ;
232
+
233
+ cloudevent
234
+ . dataContentType ( "text/plain" )
235
+ . data ( expected ) ;
236
+ expect ( cloudevent . getData ( ) ) . to . deep . equal ( expected ) ;
237
+
238
+ cloudevent . dataContentType ( olddct ) ;
239
+ } ) ;
240
+ } ) ;
227
241
} ) ;
0 commit comments