11const expect = require ( "chai" ) . expect ;
22const Spec03 = require ( "../lib/specs/spec_0_3.js" ) ;
33const { CloudEvent } = require ( "../index.js" ) ;
4+ const {
5+ MIME_JSON ,
6+ ENCODING_BASE64 ,
7+ SPEC_V03
8+ } = require ( "../lib/bindings/http/constants.js" ) ;
49
510const id = "97699ec2-a8d9-47c1-bfa0-ff7aa526f838" ;
611const type = "com.github.pull.create" ;
712const source = "urn:event:from:myapi/resourse/123" ;
813const time = new Date ( ) ;
914const schemaurl = "http://example.com/registry/myschema.json" ;
10- const dataContentEncoding = "base64" ;
11- const dataContentType = "application/json" ;
1215const data = {
1316 much : "wow"
1417} ;
@@ -19,7 +22,7 @@ const cloudevent =
1922 . id ( id )
2023 . source ( source )
2124 . type ( type )
22- . dataContentType ( dataContentType )
25+ . dataContentType ( MIME_JSON )
2326 . schemaurl ( schemaurl )
2427 . subject ( subject )
2528 . time ( time )
@@ -36,7 +39,7 @@ describe("CloudEvents Spec v0.3", () => {
3639 } ) ;
3740
3841 it ( "Should have 'specversion'" , ( ) => {
39- expect ( cloudevent . getSpecversion ( ) ) . to . equal ( "0.3" ) ;
42+ expect ( cloudevent . getSpecversion ( ) ) . to . equal ( SPEC_V03 ) ;
4043 } ) ;
4144
4245 it ( "Should have 'type'" , ( ) => {
@@ -46,14 +49,14 @@ describe("CloudEvents Spec v0.3", () => {
4649
4750 describe ( "OPTIONAL Attributes" , ( ) => {
4851 it ( "Should have 'datacontentencoding'" , ( ) => {
49- cloudevent . dataContentEncoding ( dataContentEncoding ) ;
52+ cloudevent . dataContentEncoding ( ENCODING_BASE64 ) ;
5053 expect ( cloudevent . spec . payload . datacontentencoding )
51- . to . equal ( dataContentEncoding ) ;
54+ . to . equal ( ENCODING_BASE64 ) ;
5255 delete cloudevent . spec . payload . datacontentencoding ;
5356 } ) ;
5457
5558 it ( "Should have 'datacontenttype'" , ( ) => {
56- expect ( cloudevent . getDataContentType ( ) ) . to . equal ( dataContentType ) ;
59+ expect ( cloudevent . getDataContentType ( ) ) . to . equal ( MIME_JSON ) ;
5760 } ) ;
5861
5962 it ( "Should have 'schemaurl'" , ( ) => {
@@ -119,15 +122,15 @@ describe("CloudEvents Spec v0.3", () => {
119122 expect ( cloudevent . format . bind ( cloudevent ) )
120123 . to
121124 . throw ( "invalid payload" ) ;
122- cloudevent . spec . payload . specversion = "0.3" ;
125+ cloudevent . spec . payload . specversion = SPEC_V03 ;
123126 } ) ;
124127
125128 it ( "should throw an error when is empty" , ( ) => {
126129 cloudevent . spec . payload . specversion = "" ;
127130 expect ( cloudevent . format . bind ( cloudevent ) )
128131 . to
129132 . throw ( "invalid payload" ) ;
130- cloudevent . spec . payload . specversion = "0.3" ;
133+ cloudevent . spec . payload . specversion = SPEC_V03 ;
131134 } ) ;
132135 } ) ;
133136
@@ -170,7 +173,7 @@ describe("CloudEvents Spec v0.3", () => {
170173 ( ) => {
171174 cloudevent
172175 . data ( "no base 64 value" )
173- . dataContentEncoding ( "base64" )
176+ . dataContentEncoding ( ENCODING_BASE64 )
174177 . dataContentType ( "text/plain" ) ;
175178
176179 expect ( cloudevent . format . bind ( cloudevent ) )
@@ -184,7 +187,7 @@ describe("CloudEvents Spec v0.3", () => {
184187 it ( "should accept when 'data' is a string" , ( ) => {
185188 cloudevent
186189 . data ( "Y2xvdWRldmVudHMK" )
187- . dataContentEncoding ( "base64" ) ;
190+ . dataContentEncoding ( ENCODING_BASE64 ) ;
188191 expect ( cloudevent . format ( ) ) . to . have . property ( "datacontentencoding" ) ;
189192 delete cloudevent . spec . payload . datacontentencoding ;
190193 cloudevent . data ( data ) ;
@@ -198,12 +201,12 @@ describe("CloudEvents Spec v0.3", () => {
198201 . data ( JSON . stringify ( data ) ) ;
199202
200203 expect ( typeof cloudevent . getData ( ) ) . to . equal ( "string" ) ;
201- cloudevent . dataContentType ( dataContentType ) ;
204+ cloudevent . dataContentType ( MIME_JSON ) ;
202205 } ) ;
203206
204207 it ( "should convert data with stringified json to a json object" , ( ) => {
205208 cloudevent
206- . dataContentType ( dataContentType )
209+ . dataContentType ( MIME_JSON )
207210 . data ( JSON . stringify ( data ) ) ;
208211 expect ( cloudevent . getData ( ) ) . to . deep . equal ( data ) ;
209212 } ) ;
0 commit comments