From 7d805070ff0e104d5eb89b23fb8701be822456b7 Mon Sep 17 00:00:00 2001 From: Christopher Yovanovitch Date: Thu, 4 Jul 2024 23:12:21 +0200 Subject: [PATCH] bug: add a failing test --- src/test/integration-tests.ts | 37 ++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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); + } + }); + }); +})