@@ -9,7 +9,7 @@ const contenttype = "application/json";
9
9
const data = { } ;
10
10
const extensions = { } ;
11
11
12
- var cloudevent =
12
+ var cloudevent =
13
13
new Cloudevent ( Cloudevent . specs [ "0.2" ] )
14
14
. type ( type )
15
15
. source ( source ) ;
@@ -27,6 +27,14 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
27
27
expect ( cloudevent . format ( ) ) . to . have . property ( "specversion" ) ;
28
28
} ) ;
29
29
30
+ it ( "should throw an error when mandatory attribute is absent" , ( ) => {
31
+ delete cloudevent . spec . payload . source ;
32
+ expect ( cloudevent . format . bind ( cloudevent ) )
33
+ . to
34
+ . throw ( "invalid payload" ) ;
35
+ cloudevent . spec . payload . source = source ;
36
+ } ) ;
37
+
30
38
it ( "requires 'source'" , ( ) => {
31
39
expect ( cloudevent . format ( ) ) . to . have . property ( "source" ) ;
32
40
} ) ;
@@ -47,6 +55,14 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
47
55
expect ( cloudevent . format ( ) ) . to . have . property ( "schemaurl" ) ;
48
56
} ) ;
49
57
58
+ it ( "should throw an error when 'schemaurl' is not an URI" , ( ) => {
59
+ cloudevent . spec . payload . schemaurl = "KKKKKK" ;
60
+ expect ( cloudevent . format . bind ( cloudevent ) )
61
+ . to
62
+ . throw ( "invalid payload" ) ;
63
+ cloudevent . spec . payload . schemaurl = schemaurl ;
64
+ } ) ;
65
+
50
66
it ( "contains 'contenttype'" , ( ) => {
51
67
cloudevent . contenttype ( contenttype ) ;
52
68
expect ( cloudevent . format ( ) ) . to . have . property ( "contenttype" ) ;
@@ -68,8 +84,8 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
68
84
} ) ;
69
85
70
86
it ( "should throw an error when employ reserved name as extension" , ( ) => {
71
-
72
- var cevt =
87
+
88
+ var cevt =
73
89
new Cloudevent ( Cloudevent . specs [ "0.2" ] )
74
90
. type ( type )
75
91
. source ( source ) ;
0 commit comments