Skip to content

Commit

Permalink
bug: add a failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
yovanoc committed Jul 4, 2024
1 parent e1f5dc1 commit 7d80507
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/test/integration-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
});
});
})

0 comments on commit 7d80507

Please sign in to comment.