@@ -128,7 +128,7 @@ describe('Subscribe to buffer', () => {
128
128
// when using messageBuffer, with redis instance the channel name is not a string but a buffer
129
129
const pubSub = new RedisPubSub ( { messageEventName : 'messageBuffer' } ) ;
130
130
const payload = 'This is amazing' ;
131
-
131
+
132
132
pubSub . subscribe ( 'Posts' , message => {
133
133
try {
134
134
expect ( message ) . to . be . instanceOf ( Buffer ) ;
@@ -173,3 +173,39 @@ describe('PubSubCluster', () => {
173
173
} ) ;
174
174
} ) . timeout ( 2000 ) ;
175
175
} ) ;
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 . instanceOf ( Buffer ) ;
198
+ expect ( message . toString ( 'utf-8' ) ) . to . be . equal ( payload ) ;
199
+ done ( ) ;
200
+ } catch ( e ) {
201
+ done ( e ) ;
202
+ }
203
+ } ) . then ( async subId => {
204
+ try {
205
+ await pubSub . publish ( 'Posts' , payload ) ;
206
+ } catch ( e ) {
207
+ done ( e ) ;
208
+ }
209
+ } ) ;
210
+ } ) ;
211
+ } )
0 commit comments