@@ -6,7 +6,7 @@ import CONSTANTS from "../../src/constants";
6
6
const DEFAULT_CE_CONTENT_TYPE = CONSTANTS . DEFAULT_CE_CONTENT_TYPE ;
7
7
const DEFAULT_CONTENT_TYPE = CONSTANTS . DEFAULT_CONTENT_TYPE ;
8
8
9
- import { CloudEvent , Version , Emitter , Protocol , headersFor } from "../../src" ;
9
+ import { CloudEvent , Version , Emitter , Protocol , headersFor , TransportOptions } from "../../src" ;
10
10
import { AxiosResponse } from "axios" ;
11
11
12
12
const receiver = "https://cloudevents.io/" ;
@@ -40,7 +40,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
40
40
} ) ;
41
41
42
42
describe ( "V1" , ( ) => {
43
- const emitter = new Emitter ( { url : receiver } ) ;
43
+ const send = ( e : CloudEvent , opts : TransportOptions = { } ) => Emitter . send ( e , { url : receiver , ... opts } ) ;
44
44
const event = new CloudEvent ( {
45
45
type,
46
46
source,
@@ -52,8 +52,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
52
52
} ) ;
53
53
54
54
it ( "Sends a binary 1.0 CloudEvent by default" , ( ) =>
55
- emitter
56
- . send ( event )
55
+ send ( event )
57
56
. then ( ( response : AxiosResponse ) => {
58
57
// A binary message will have a ce-id header
59
58
expect ( response . data [ "content-type" ] ) . to . equal ( DEFAULT_CONTENT_TYPE ) ;
@@ -78,8 +77,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
78
77
} ) ;
79
78
80
79
it ( "Sends a binary CloudEvent with Custom Headers" , ( ) =>
81
- emitter
82
- . send ( event , { headers : { customheader : "value" } } )
80
+ send ( event , { headers : { customheader : "value" } } )
83
81
. then ( ( response : { data : { [ k : string ] : string } } ) => {
84
82
// A binary message will have a ce-id header
85
83
expect ( response . data . customheader ) . to . equal ( "value" ) ;
@@ -92,8 +90,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
92
90
. catch ( expect . fail ) ) ;
93
91
94
92
it ( "Sends a structured 1.0 CloudEvent if specified" , ( ) =>
95
- emitter
96
- . send ( event , { protocol : Protocol . HTTPStructured } )
93
+ send ( event , { protocol : Protocol . HTTPStructured } )
97
94
. then ( ( response : { data : { [ k : string ] : string | Record < string , string > ; data : { lunchBreak : string } } } ) => {
98
95
// A structured message will have a cloud event content type
99
96
expect ( response . data [ "content-type" ] ) . to . equal ( DEFAULT_CE_CONTENT_TYPE ) ;
@@ -121,8 +118,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
121
118
return [ 201 , returnBody ] ;
122
119
} ) ;
123
120
124
- return emitter
125
- . send ( event , { protocol : Protocol . HTTPStructured , url : `${ receiver } alternate` } )
121
+ return send ( event , { protocol : Protocol . HTTPStructured , url : `${ receiver } alternate` } )
126
122
. then ( ( response : AxiosResponse ) => {
127
123
// A structured message will have a cloud event content type
128
124
expect ( response . data [ "content-type" ] ) . to . equal ( DEFAULT_CE_CONTENT_TYPE ) ;
@@ -137,7 +133,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
137
133
} ) ;
138
134
139
135
describe ( "V03" , ( ) => {
140
- const emitter = new Emitter ( { url : receiver } ) ;
136
+ const send = ( e : CloudEvent , opts : TransportOptions = { } ) => Emitter . send ( e , { url : receiver , ... opts } ) ;
141
137
const event = new CloudEvent ( {
142
138
specversion : Version . V03 ,
143
139
type,
@@ -150,8 +146,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
150
146
} ) ;
151
147
152
148
it ( "Sends a binary 0.3 CloudEvent" , ( ) =>
153
- emitter
154
- . send ( event )
149
+ send ( event )
155
150
. then ( ( response : AxiosResponse ) => {
156
151
// A binary message will have a ce-id header
157
152
expect ( response . data [ CONSTANTS . CE_HEADERS . ID ] ) . to . equal ( event . id ) ;
@@ -175,8 +170,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
175
170
} ) ;
176
171
177
172
it ( "Sends a structured 0.3 CloudEvent if specified" , ( ) =>
178
- emitter
179
- . send ( event , { protocol : Protocol . HTTPStructured } )
173
+ send ( event , { protocol : Protocol . HTTPStructured } )
180
174
. then (
181
175
( response : {
182
176
data : { [ k : string ] : string | Record < string , string > ; specversion : string ; data : { lunchBreak : string } } ;
@@ -208,8 +202,7 @@ describe("HTTP Transport Binding Emitter for CloudEvents", () => {
208
202
return [ 201 , returnBody ] ;
209
203
} ) ;
210
204
211
- return emitter
212
- . send ( event , { protocol : Protocol . HTTPStructured , url : `${ receiver } alternate` } )
205
+ return send ( event , { protocol : Protocol . HTTPStructured , url : `${ receiver } alternate` } )
213
206
. then (
214
207
( response : {
215
208
data : { specversion : string ; data : { lunchBreak : string } ; [ k : string ] : string | Record < string , string > } ;
0 commit comments