@@ -344,7 +344,7 @@ describe('3rd Party Broker API', function () {
344344 cookies : { sid : TestObjects . tokens . bob } ,
345345 body : [
346346 {
347- topic : 'bar/baz/qux' ,
347+ topic : 'bar/baz/qux/x ' ,
348348 metadata : { description : 'a topic' }
349349 }
350350 ]
@@ -359,18 +359,21 @@ describe('3rd Party Broker API', function () {
359359 } )
360360 response . statusCode . should . equal ( 200 )
361361 const result = response . json ( )
362- result . topics . should . have . a . lengthOf ( 3 )
362+ result . topics . should . have . a . lengthOf ( 4 )
363363 const topics = result . topics
364364 topics . sort ( ( A , B ) => A . topic . localeCompare ( B . topic ) )
365365
366366 topics [ 0 ] . should . have . property ( 'topic' , 'bar/baz/qux' )
367- topics [ 0 ] . should . have . property ( 'metadata' , { description : 'a topic' } )
367+ topics [ 0 ] . should . have . property ( 'metadata' , { } )
368368
369- topics [ 1 ] . should . have . property ( 'topic' , 'foo/ bar/baz' )
370- topics [ 1 ] . should . have . property ( 'metadata' , { } )
369+ topics [ 1 ] . should . have . property ( 'topic' , 'bar/baz/qux/x ' )
370+ topics [ 1 ] . should . have . property ( 'metadata' , { description : 'a topic' } )
371371
372- topics [ 2 ] . should . have . property ( 'topic' , 'foo/bar/baz/qux ' )
372+ topics [ 2 ] . should . have . property ( 'topic' , 'foo/bar/baz' )
373373 topics [ 2 ] . should . have . property ( 'metadata' , { } )
374+
375+ topics [ 3 ] . should . have . property ( 'topic' , 'foo/bar/baz/qux' )
376+ topics [ 3 ] . should . have . property ( 'metadata' , { } )
374377 } )
375378 it ( 'Get Topics for 3rd Pary broker as a Team Owner' , async function ( ) {
376379 const response = await app . inject ( {
@@ -380,7 +383,7 @@ describe('3rd Party Broker API', function () {
380383 } )
381384 response . statusCode . should . equal ( 200 )
382385 const result = response . json ( )
383- result . topics . should . have . a . lengthOf ( 3 )
386+ result . topics . should . have . a . lengthOf ( 4 )
384387 } )
385388 it ( 'Add Metadata to a Topic' , async function ( ) {
386389 let response = await app . inject ( {
@@ -390,7 +393,7 @@ describe('3rd Party Broker API', function () {
390393 } )
391394 response . statusCode . should . equal ( 200 )
392395 let result = response . json ( )
393- result . topics . should . have . a . lengthOf ( 3 )
396+ result . topics . should . have . a . lengthOf ( 4 )
394397 result . topics [ 0 ] . should . have . property ( 'id' )
395398 result . topics [ 0 ] . should . have . property ( 'topic' )
396399 const topicId = result . topics [ 0 ] . id
@@ -420,7 +423,7 @@ describe('3rd Party Broker API', function () {
420423 } )
421424 response . statusCode . should . equal ( 200 )
422425 let result = response . json ( )
423- result . topics . should . have . a . lengthOf ( 3 )
426+ result . topics . should . have . a . lengthOf ( 4 )
424427 result . topics [ 0 ] . should . have . property ( 'id' )
425428 result . topics [ 0 ] . should . have . property ( 'topic' )
426429 const topicId = result . topics [ 0 ] . id
@@ -439,8 +442,76 @@ describe('3rd Party Broker API', function () {
439442 } )
440443 response . statusCode . should . equal ( 200 )
441444 result = response . json ( )
442- result . count . should . equal ( 2 )
445+ result . count . should . equal ( 3 )
443446 } )
447+
448+ it ( 'Topic Cache' , async function ( ) {
449+ const response = await app . inject ( {
450+ method : 'POST' ,
451+ url : `/api/v1/teams/${ app . team . hashid } /brokers/${ brokerCredentialId } /topics` ,
452+ cookies : { sid : TestObjects . tokens . bob } ,
453+ body : [
454+ {
455+ topic : 'bar/baz/qux' ,
456+ metadata : { description : 'a topic' }
457+ }
458+ ]
459+ } )
460+ response . statusCode . should . equal ( 201 )
461+
462+ const responseTopics = await app . inject ( {
463+ method : 'GET' ,
464+ url : `/api/v1/teams/${ app . team . hashid } /brokers/${ brokerCredentialId } /topics` ,
465+ cookies : { sid : TestObjects . tokens . bob }
466+ } )
467+ const result = responseTopics . json ( )
468+
469+ const topic = await app . db . models . MQTTTopicSchema . get ( app . team . hashid , brokerCredentialId , result . topics [ 0 ] . id )
470+ await app . inject ( {
471+ method : 'POST' ,
472+ url : `/api/v1/teams/${ app . team . hashid } /brokers/${ brokerCredentialId } /topics` ,
473+ cookies : { sid : TestObjects . tokens . bob } ,
474+ body : [
475+ {
476+ topic : 'bar/baz/qux' ,
477+ metadata : { description : 'a topic' }
478+ }
479+ ]
480+ } )
481+
482+ const topicSecond = await app . db . models . MQTTTopicSchema . get ( app . team . hashid , brokerCredentialId , result . topics [ 0 ] . id )
483+
484+ topicSecond . updatedAt . toISOString ( ) . should . equal ( topic . updatedAt . toISOString ( ) )
485+ const response2 = await app . inject ( {
486+ method : 'DELETE' ,
487+ url : `/api/v1/teams/${ app . team . hashid } /brokers/${ brokerCredentialId } /topics/${ result . topics [ 0 ] . id } ` ,
488+ cookies : { sid : TestObjects . tokens . bob }
489+ } )
490+ response2 . statusCode . should . equal ( 201 )
491+
492+ await app . inject ( {
493+ method : 'POST' ,
494+ url : `/api/v1/teams/${ app . team . hashid } /brokers/${ brokerCredentialId } /topics` ,
495+ cookies : { sid : TestObjects . tokens . bob } ,
496+ body : [
497+ {
498+ topic : 'bar/baz/qux' ,
499+ metadata : { description : 'a topic' }
500+ }
501+ ]
502+ } )
503+
504+ const responseTopics2 = await app . inject ( {
505+ method : 'GET' ,
506+ url : `/api/v1/teams/${ app . team . hashid } /brokers/${ brokerCredentialId } /topics` ,
507+ cookies : { sid : TestObjects . tokens . bob }
508+ } )
509+ const result2 = responseTopics2 . json ( )
510+
511+ const topicThird = await app . db . models . MQTTTopicSchema . get ( app . team . hashid , brokerCredentialId , result2 . topics [ 0 ] . id )
512+ topicThird . updatedAt . toISOString ( ) . should . not . equal ( topic . updatedAt . toISOString ( ) )
513+ } )
514+
444515 describe ( 'Team Broker' , function ( ) {
445516 before ( async function ( ) {
446517 app . team2 = await app . factory . createTeam ( { name : 'BTeam' } )
0 commit comments