@@ -9,9 +9,10 @@ const contenttype = "application/json";
9
9
const data = { } ;
10
10
const extensions = { } ;
11
11
12
- var cloudevent = new Cloudevent ( Cloudevent . specs [ "0.2" ] )
13
- . type ( type )
14
- . source ( source ) ;
12
+ var cloudevent =
13
+ new Cloudevent ( Cloudevent . specs [ "0.2" ] )
14
+ . type ( type )
15
+ . source ( source ) ;
15
16
16
17
describe ( "CloudEvents Spec 0.2 - JavaScript SDK" , ( ) => {
17
18
@@ -65,6 +66,17 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
65
66
cloudevent . addExtension ( "extension2" , "value2" ) ;
66
67
expect ( cloudevent . format ( ) [ "extension2" ] ) . to . equal ( "value2" ) ;
67
68
} ) ;
69
+
70
+ it ( "should throw an error when employ reserved name as extension" , ( ) => {
71
+
72
+ var cevt =
73
+ new Cloudevent ( Cloudevent . specs [ "0.2" ] )
74
+ . type ( type )
75
+ . source ( source ) ;
76
+ expect ( cevt . addExtension . bind ( cevt , "id" ) )
77
+ . to
78
+ . throw ( "Reserved attribute name: 'id'" ) ;
79
+ } ) ;
68
80
} ) ;
69
81
70
82
describe ( "The Constraints check" , ( ) => {
@@ -73,7 +85,7 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
73
85
cloudevent . type ( "" ) ;
74
86
expect ( cloudevent . format . bind ( cloudevent ) )
75
87
. to
76
- . throw ( "'type' is invalid" ) ;
88
+ . throw ( "invalid payload " ) ;
77
89
} ) ;
78
90
79
91
it ( "must be a non-empty string" , ( ) => {
@@ -95,7 +107,15 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
95
107
cloudevent . spec . payload . specversion = "" ;
96
108
expect ( cloudevent . format . bind ( cloudevent ) )
97
109
. to
98
- . throw ( "'specversion' is invalid" ) ;
110
+ . throw ( "invalid payload" ) ;
111
+ cloudevent . spec . payload . specversion = "0.2" ;
112
+ } ) ;
113
+
114
+ it ( "should throw an error when the value is not '0.2'" , ( ) => {
115
+ cloudevent . spec . payload . specversion = "0.4" ;
116
+ expect ( cloudevent . format . bind ( cloudevent ) )
117
+ . to
118
+ . throw ( "invalid payload" ) ;
99
119
cloudevent . spec . payload . specversion = "0.2" ;
100
120
} ) ;
101
121
} ) ;
@@ -105,7 +125,7 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
105
125
cloudevent . id ( "" ) ;
106
126
expect ( cloudevent . format . bind ( cloudevent ) )
107
127
. to
108
- . throw ( "'id' is invalid" ) ;
128
+ . throw ( "invalid payload " ) ;
109
129
} ) ;
110
130
it ( "must be a non-empty string" , ( ) => {
111
131
cloudevent . id ( "my.id-0x0090" ) ;
0 commit comments