@@ -154,7 +154,7 @@ describe("common/server", () => {
154
154
155
155
describe ( "pubsub" , ( ) => {
156
156
runIt (
157
- "should by default mark messagess as processed successfully (SUCCESS) and the same message should not be received anymore" ,
157
+ "should mark messages as processed successfully (SUCCESS) by-default, and the same message should not be received anymore" ,
158
158
async ( server : DaprServer , protocol : string ) => {
159
159
const res = await server . client . pubsub . publish ( pubSubName , getTopic ( topicWithStatusCb , protocol ) , "SUCCESS" ) ;
160
160
expect ( res . error ) . toBeUndefined ( ) ;
@@ -170,7 +170,7 @@ describe("common/server", () => {
170
170
) ;
171
171
172
172
runIt (
173
- "should mark messagess as retried (RETRY) and the same message should be received again until we send SUCCESS" ,
173
+ "should mark messages as retried (RETRY), and the same message should be received again until we send SUCCESS" ,
174
174
async ( server : DaprServer , protocol : string ) => {
175
175
const res = await server . client . pubsub . publish (
176
176
pubSubName ,
@@ -189,7 +189,7 @@ describe("common/server", () => {
189
189
) ;
190
190
191
191
runIt (
192
- "should mark messagess as dropped (DROP) and the message should be deadlettered" ,
192
+ "should mark messages as dropped (DROP), and the message should be deadlettered" ,
193
193
async ( server : DaprServer , protocol : string ) => {
194
194
const res = await server . client . pubsub . publish ( pubSubName , getTopic ( topicWithStatusCb , protocol ) , "DROP" ) ;
195
195
expect ( res . error ) . toBeUndefined ( ) ;
@@ -229,7 +229,7 @@ describe("common/server", () => {
229
229
{
230
230
message : "Message 1!" ,
231
231
} ,
232
- { rawPayload : "true" } ,
232
+ { metadata : { rawPayload : "true" } } ,
233
233
) ;
234
234
235
235
const res2 = await server . client . pubsub . publish (
@@ -238,7 +238,7 @@ describe("common/server", () => {
238
238
{
239
239
message : "Message 2!" ,
240
240
} ,
241
- { rawPayload : "true" } ,
241
+ { metadata : { rawPayload : "true" } } ,
242
242
) ;
243
243
244
244
expect ( res1 . error ) . toBeUndefined ( ) ;
@@ -320,7 +320,7 @@ describe("common/server", () => {
320
320
{
321
321
message : "Message 1!" ,
322
322
} ,
323
- { rawPayload : "true" } ,
323
+ { metadata : { rawPayload : "true" } } ,
324
324
) ;
325
325
326
326
const res2 = await server . client . pubsub . publish (
@@ -329,7 +329,7 @@ describe("common/server", () => {
329
329
{
330
330
message : "Message 2!" ,
331
331
} ,
332
- { rawPayload : "true" } ,
332
+ { metadata : { rawPayload : "true" } } ,
333
333
) ;
334
334
335
335
expect ( res1 . error ) . toBeUndefined ( ) ;
@@ -355,7 +355,7 @@ describe("common/server", () => {
355
355
expect ( mockSubscribeHandler . mock . calls [ 0 ] [ 0 ] ) . toEqual ( { message : "Hello, world!" } ) ;
356
356
} ) ;
357
357
358
- runIt ( "should be able to send and receive cloud events " , async ( server : DaprServer , protocol : string ) => {
358
+ runIt ( "should be able to send and receive cloudevents " , async ( server : DaprServer , protocol : string ) => {
359
359
const ce = {
360
360
specversion : "1.0" ,
361
361
type : "com.github.pull.create" ,
@@ -375,6 +375,28 @@ describe("common/server", () => {
375
375
expect ( mockSubscribeHandler . mock . calls [ 0 ] [ 0 ] ) . toEqual ( "Hello, world!" ) ;
376
376
} ) ;
377
377
378
+ runIt ( "should be able to send cloudevents as JSON and receive it" , async ( server : DaprServer , protocol : string ) => {
379
+ const ce = {
380
+ specversion : "1.0" ,
381
+ type : "com.github.pull.create" ,
382
+ source : "https://github.com/cloudevents/spec/pull" ,
383
+ id : "A234-1234-1234" ,
384
+ data : "Hello, world!" ,
385
+ datacontenttype : "text/plain" ,
386
+ } ;
387
+
388
+ const options = { contentType : "application/json" } ;
389
+ const res = await server . client . pubsub . publish ( pubSubName , getTopic ( topicDefault , protocol ) , ce , options ) ;
390
+ expect ( res . error ) . toBeUndefined ( ) ;
391
+
392
+ // Delay a bit for event to arrive
393
+ await new Promise ( ( resolve , _reject ) => setTimeout ( resolve , 500 ) ) ;
394
+ expect ( mockSubscribeHandler . mock . calls . length ) . toBe ( 1 ) ;
395
+ // The cloudevent should contain an inner cloudevent since the content type was application/json
396
+ const innerCe : any = mockSubscribeHandler . mock . calls [ 0 ] [ 0 ] ;
397
+ expect ( innerCe [ "data" ] ) . toEqual ( "Hello, world!" ) ;
398
+ } ) ;
399
+
378
400
runIt (
379
401
"should be able to send plain events and receive as raw payload" ,
380
402
async ( server : DaprServer , protocol : string ) => {
@@ -418,7 +440,7 @@ describe("common/server", () => {
418
440
pubSubName ,
419
441
getTopic ( topicRawPayload , protocol ) ,
420
442
"Hello, world!" ,
421
- { rawPayload : "true" } ,
443
+ { metadata : { rawPayload : "true" } } ,
422
444
) ;
423
445
expect ( res . error ) . toBeUndefined ( ) ;
424
446
@@ -437,7 +459,7 @@ describe("common/server", () => {
437
459
pubSubName ,
438
460
getTopic ( topicRawPayload , protocol ) ,
439
461
{ message : "Hello, world!" } ,
440
- { rawPayload : "true" } ,
462
+ { metadata : { rawPayload : "true" } } ,
441
463
) ;
442
464
expect ( res . error ) . toBeUndefined ( ) ;
443
465
0 commit comments