Skip to content

Commit 3fef7bf

Browse files
committed
bug: add a failing test
1 parent e1f5dc1 commit 3fef7bf

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/test/integration-tests.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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,39 @@ 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.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

Comments
 (0)