@@ -9,9 +9,10 @@ const contenttype = "application/json";
99const data = { } ;
1010const extensions = { } ;
1111
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 ) ;
1516
1617describe ( "CloudEvents Spec 0.2 - JavaScript SDK" , ( ) => {
1718
@@ -65,6 +66,17 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
6566 cloudevent . addExtension ( "extension2" , "value2" ) ;
6667 expect ( cloudevent . format ( ) [ "extension2" ] ) . to . equal ( "value2" ) ;
6768 } ) ;
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+ } ) ;
6880 } ) ;
6981
7082 describe ( "The Constraints check" , ( ) => {
@@ -73,7 +85,7 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
7385 cloudevent . type ( "" ) ;
7486 expect ( cloudevent . format . bind ( cloudevent ) )
7587 . to
76- . throw ( "'type' is invalid" ) ;
88+ . throw ( "invalid payload " ) ;
7789 } ) ;
7890
7991 it ( "must be a non-empty string" , ( ) => {
@@ -95,7 +107,15 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
95107 cloudevent . spec . payload . specversion = "" ;
96108 expect ( cloudevent . format . bind ( cloudevent ) )
97109 . 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" ) ;
99119 cloudevent . spec . payload . specversion = "0.2" ;
100120 } ) ;
101121 } ) ;
@@ -105,7 +125,7 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
105125 cloudevent . id ( "" ) ;
106126 expect ( cloudevent . format . bind ( cloudevent ) )
107127 . to
108- . throw ( "'id' is invalid" ) ;
128+ . throw ( "invalid payload " ) ;
109129 } ) ;
110130 it ( "must be a non-empty string" , ( ) => {
111131 cloudevent . id ( "my.id-0x0090" ) ;
0 commit comments