@@ -128,7 +128,7 @@ describe('Subscribe to buffer', () => {
128128 // when using messageBuffer, with redis instance the channel name is not a string but a buffer
129129 const pubSub = new RedisPubSub ( { messageEventName : 'messageBuffer' } ) ;
130130 const payload = 'This is amazing' ;
131-
131+
132132 pubSub . subscribe ( 'Posts' , message => {
133133 try {
134134 expect ( message ) . to . be . instanceOf ( Buffer ) ;
@@ -173,3 +173,38 @@ describe('PubSubCluster', () => {
173173 } ) ;
174174 } ) . timeout ( 2000 ) ;
175175} ) ;
176+
177+
178+ describe ( "Don't transform wanted types" , ( ) => {
179+ it ( 'base64 string in serializer' , done => {
180+ const payload = 'This is amazing' ;
181+
182+ // when using messageBuffer, with redis instance the channel name is not a string but a buffer
183+ const pubSub = new RedisPubSub ( {
184+ // messageEventName: 'messageBuffer',
185+ serializer : v => Buffer . from ( v ) . toString ( 'base64' ) ,
186+ deserializer : v => {
187+ if ( typeof v === 'string' ) {
188+ return Buffer . from ( v , 'base64' ) . toString ( 'utf-8' ) ;
189+ }
190+
191+ throw new Error ( 'Invalid data' ) ;
192+ }
193+ } ) ;
194+
195+ pubSub . subscribe ( 'Posts' , message => {
196+ try {
197+ expect ( message ) . to . be . equal ( payload ) ;
198+ done ( ) ;
199+ } catch ( e ) {
200+ done ( e ) ;
201+ }
202+ } ) . then ( async subId => {
203+ try {
204+ await pubSub . publish ( 'Posts' , payload ) ;
205+ } catch ( e ) {
206+ done ( e ) ;
207+ }
208+ } ) ;
209+ } ) ;
210+ } )
0 commit comments