@@ -59,6 +59,46 @@ function gotEmitter(message: Message, options?: Options): Promise<unknown> {
59
59
) ;
60
60
}
61
61
62
+ describe ( "emitterFor() defaults" , ( ) => {
63
+ it ( "Defaults to HTTP binding, binary mode" , ( ) => {
64
+ function transport ( message : Message ) : Promise < unknown > {
65
+ // A binary message will have the source attribute as a header
66
+ expect ( message . headers [ CONSTANTS . CE_HEADERS . TYPE ] ) . to . equal ( "emitter.test" ) ;
67
+ return Promise . resolve ( ) ;
68
+ }
69
+ const emitter = emitterFor ( transport ) ;
70
+ emitter (
71
+ new CloudEvent ( {
72
+ id : "1234" ,
73
+ source : "/emitter/test" ,
74
+ type : "emitter.test" ,
75
+ } ) ,
76
+ ) ;
77
+ } ) ;
78
+
79
+ it ( "Supports HTTP binding, structured mode" , ( ) => {
80
+ function transport ( message : Message ) : Promise < unknown > {
81
+ console . error ( message ) ;
82
+ // A structured message will have the application/cloudevents+json header
83
+ expect ( message . headers [ "content-type" ] ) . to . equal ( CONSTANTS . DEFAULT_CE_CONTENT_TYPE ) ;
84
+ const body = JSON . parse ( message . body as string ) ;
85
+ expect ( body . id ) . to . equal ( "1234" ) ;
86
+ return Promise . resolve ( ) ;
87
+ }
88
+ // Ignore the next line to ensure that HTTP transport is still the default.
89
+ // Otherwise, tslint would complain that the param did not have `binding: <val>`
90
+ /* @ts -ignore */
91
+ const emitter = emitterFor ( transport , { mode : Mode . STRUCTURED } ) ;
92
+ emitter (
93
+ new CloudEvent ( {
94
+ id : "1234" ,
95
+ source : "/emitter/test" ,
96
+ type : "emitter.test" ,
97
+ } ) ,
98
+ ) ;
99
+ } ) ;
100
+ } ) ;
101
+
62
102
describe ( "HTTP Transport Binding for emitterFactory" , ( ) => {
63
103
beforeEach ( ( ) => {
64
104
nock ( sink )
0 commit comments