@@ -13,7 +13,7 @@ const { Key } = require('interface-datastore')
13
13
const { Record } = require ( 'libp2p-record' )
14
14
15
15
const DatastorePubsub = require ( '../src' )
16
- const { keyToTopic } = require ( '../src/utils' )
16
+ const { keyToTopic, topicToKey } = require ( '../src/utils' )
17
17
const { connect, waitFor, waitForPeerToSubscribe, spawnDaemon, stopDaemon } = require ( './utils' )
18
18
const promisify = require ( 'promisify-es6' )
19
19
@@ -426,8 +426,8 @@ describe('datastore-pubsub', function () {
426
426
} )
427
427
428
428
it ( 'should subscribe the topic and after a message being received, discard it using the subscriptionKeyFn' , async ( ) => {
429
- const subscriptionKeyFn = ( topic ) => {
430
- expect ( topic ) . to . equal ( `/${ keyRef } ` )
429
+ const subscriptionKeyFn = ( key ) => {
430
+ expect ( key . toString ( ) ) . to . equal ( `/${ keyRef } ` )
431
431
throw new Error ( 'DISCARD MESSAGE' )
432
432
}
433
433
const dsPubsubA = new DatastorePubsub ( pubsubA , datastoreA , peerIdA , smoothValidator )
@@ -469,14 +469,14 @@ describe('datastore-pubsub', function () {
469
469
} )
470
470
471
471
it ( 'should subscribe the topic and after a message being received, change its key using subscriptionKeyFn' , async ( ) => {
472
- const subscriptionKeyFn = ( topic ) => {
473
- expect ( topic ) . to . equal ( key . toString ( ) )
474
- return `${ topic } new`
472
+ const subscriptionKeyFn = ( key ) => {
473
+ expect ( key . toString ( ) ) . to . equal ( `/ ${ keyRef } ` )
474
+ return topicToKey ( `${ keyToTopic ( key ) } new` )
475
475
}
476
476
const dsPubsubA = new DatastorePubsub ( pubsubA , datastoreA , peerIdA , smoothValidator )
477
477
const dsPubsubB = new DatastorePubsub ( pubsubB , datastoreB , peerIdB , smoothValidator , subscriptionKeyFn )
478
478
const subsTopic = keyToTopic ( `/${ keyRef } ` )
479
- const keyNew = Buffer . from ( `${ key . toString ( ) } new` )
479
+ const keyNew = topicToKey ( `${ keyToTopic ( key ) } new` )
480
480
let receivedMessage = false
481
481
482
482
function messageHandler ( ) {
0 commit comments