Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: add a failing test #627

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/redis-pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class RedisPubSub implements PubSubEngine {
delete this.subscriptionMap[subId];
}

public asyncIterator<T>(triggers: string | string[], options?: unknown): AsyncIterator<T> {
public asyncIterator<T>(triggers: string | string[], options?: unknown): AsyncIterableIterator<T> {
return new PubSubAsyncIterator<T>(this, triggers, options);
}

Expand Down
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);
}
});
});
})
Loading