diff --git a/src/redis-pubsub.ts b/src/redis-pubsub.ts index 9ca6f48..c2d586c 100644 --- a/src/redis-pubsub.ts +++ b/src/redis-pubsub.ts @@ -168,7 +168,7 @@ export class RedisPubSub implements PubSubEngine { delete this.subscriptionMap[subId]; } - public asyncIterator(triggers: string | string[], options?: unknown): AsyncIterator { + public asyncIterator(triggers: string | string[], options?: unknown): AsyncIterableIterator { return new PubSubAsyncIterator(this, triggers, options); } diff --git a/src/test/integration-tests.ts b/src/test/integration-tests.ts index 04a6132..0c52e5a 100644 --- a/src/test/integration-tests.ts +++ b/src/test/integration-tests.ts @@ -128,7 +128,7 @@ describe('Subscribe to buffer', () => { // when using messageBuffer, with redis instance the channel name is not a string but a buffer const pubSub = new RedisPubSub({ messageEventName: 'messageBuffer'}); const payload = 'This is amazing'; - + pubSub.subscribe('Posts', message => { try { expect(message).to.be.instanceOf(Buffer); @@ -173,3 +173,38 @@ describe('PubSubCluster', () => { }); }).timeout(2000); }); + + +describe("Don't transform wanted types", () => { + it('base64 string in serializer' , done => { + const payload = 'This is amazing'; + + // when using messageBuffer, with redis instance the channel name is not a string but a buffer + const pubSub = new RedisPubSub({ + // messageEventName: 'messageBuffer', + serializer: v => Buffer.from(v).toString('base64'), + deserializer: v => { + if (typeof v === 'string') { + return Buffer.from(v, 'base64').toString('utf-8'); + } + + throw new Error('Invalid data'); + } + }); + + pubSub.subscribe('Posts', message => { + try { + expect(message).to.be.equal(payload); + done(); + } catch (e) { + done(e); + } + }).then(async subId => { + try { + await pubSub.publish('Posts', payload); + } catch (e) { + done(e); + } + }); + }); +})