@@ -367,31 +367,32 @@ describe('grpc/client', () => {
367
367
// expect(conf.items.filter(i => i.key == "myconfigkey1")[0].metadata).toHaveProperty("hello");
368
368
} ) ;
369
369
370
- // // @todo : figure out, subscribe doesn't pass keys but doesn't listen to anything?
371
- // // https://github.com/dapr/dapr/issues/4529
372
- // it('should be able to subscribe to configuration item changes on all keys', async () => {
373
- // const m = jest.fn(async (res: SubscribeConfigurationResponse) => { } );
370
+ it ( 'should be able to subscribe to configuration item changes on all keys' , async ( ) => {
371
+ const m = jest . fn ( async ( _res : SubscribeConfigurationResponse ) => { return ; } ) ;
372
+
373
+ const stream = await client . configuration . subscribe ( "config-redis" , m ) ;
374
374
375
- // console.log("Creating Subscription");
376
- // await client.configuration.subscribe("config- redis", m );
375
+ // Update the configuration item
376
+ await DockerUtils . executeDockerCommand ( "dapr_redis redis-cli MSET myconfigkey3 mynewvalue||2" ) ;
377
377
378
- // // Change an item
379
- // await DockerUtils.executeDockerCommand("dapr_redis redis-cli MSET myconfigkey3 mynewvalue||1");
378
+ expect ( m . mock . calls [ 0 ] [ 0 ] . items . length ) . toEqual ( 1 ) ;
379
+ expect ( m . mock . calls [ 0 ] [ 0 ] . items [ 0 ] . key ) . toEqual ( "myconfigkey3" ) ;
380
+ expect ( m . mock . calls [ 0 ] [ 0 ] . items [ 0 ] . value ) . toEqual ( "mynewvalue" ) ;
380
381
381
- // expect(m.mock.calls.length).toEqual(1 );
382
- // });
382
+ stream . stop ( ) ;
383
+ } ) ;
383
384
384
385
it ( 'should be able to subscribe to configuration item changes on specific keys' , async ( ) => {
385
386
const m = jest . fn ( async ( _res : SubscribeConfigurationResponse ) => { return ; } ) ;
386
387
387
- const stream1 = await client . configuration . subscribeWithKeys ( "config-redis" , [ "myconfigkey1" , "myconfigkey2" ] , m ) ;
388
+ const stream = await client . configuration . subscribeWithKeys ( "config-redis" , [ "myconfigkey1" , "myconfigkey2" ] , m ) ;
388
389
await DockerUtils . executeDockerCommand ( "dapr_redis redis-cli MSET myconfigkey1 key1_mynewvalue||1" ) ;
389
390
390
391
expect ( m . mock . calls . length ) . toEqual ( 1 ) ;
391
392
expect ( m . mock . calls [ 0 ] [ 0 ] . items [ 0 ] . key ) . toEqual ( "myconfigkey1" ) ;
392
393
expect ( m . mock . calls [ 0 ] [ 0 ] . items [ 0 ] . value ) . toEqual ( "key1_mynewvalue" ) ;
393
394
394
- await stream1 . stop ( ) ;
395
+ await stream . stop ( ) ;
395
396
} ) ;
396
397
397
398
it ( 'should be able to subscribe with metadata' , async ( ) => {
@@ -410,14 +411,14 @@ describe('grpc/client', () => {
410
411
it ( 'should be able to unsubscribe' , async ( ) => {
411
412
const m = jest . fn ( async ( _res : SubscribeConfigurationResponse ) => { return ; } ) ;
412
413
413
- const stream1 = await client . configuration . subscribeWithMetadata ( "config-redis" , [ "myconfigkey1" , "myconfigkey2" ] , { "hello" : "world" } , m ) ;
414
+ const stream = await client . configuration . subscribeWithMetadata ( "config-redis" , [ "myconfigkey1" , "myconfigkey2" ] , { "hello" : "world" } , m ) ;
414
415
await DockerUtils . executeDockerCommand ( "dapr_redis redis-cli MSET myconfigkey1 key1_mynewvalue||1" ) ;
415
416
416
417
expect ( m . mock . calls . length ) . toEqual ( 1 ) ;
417
418
expect ( m . mock . calls [ 0 ] [ 0 ] . items [ 0 ] . key ) . toEqual ( "myconfigkey1" ) ;
418
419
expect ( m . mock . calls [ 0 ] [ 0 ] . items [ 0 ] . value ) . toEqual ( "key1_mynewvalue" ) ;
419
420
420
- await stream1 . stop ( ) ;
421
+ stream . stop ( ) ;
421
422
422
423
await DockerUtils . executeDockerCommand ( "dapr_redis redis-cli MSET myconfigkey1 key1_mynewvalue2||1" ) ;
423
424
@@ -444,8 +445,8 @@ describe('grpc/client', () => {
444
445
expect ( m2 . mock . calls [ 0 ] [ 0 ] . items [ 0 ] . key ) . toEqual ( "myconfigkey1" ) ;
445
446
expect ( m2 . mock . calls [ 0 ] [ 0 ] . items [ 0 ] . value ) . toEqual ( "key1_mynewvalue" ) ;
446
447
447
- await stream1 . stop ( ) ;
448
- await stream2 . stop ( ) ;
448
+ stream1 . stop ( ) ;
449
+ stream2 . stop ( ) ;
449
450
} ) ;
450
451
} ) ;
451
452
} ) ;
0 commit comments