Skip to content

Commit 7d80507

Browse files
committed
bug: add a failing test
1 parent e1f5dc1 commit 7d80507

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/test/integration-tests.ts

Lines changed: 36 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,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

Comments
 (0)