Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
Signed-off-by: palani <palam.c@gmail.com>
  • Loading branch information
palamccc committed Feb 20, 2024
1 parent bb1a4d6 commit cd30156
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions packages/rsocket-core/src/__tests__/RSocketServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {genMockConnection} from 'MockDuplexConnection';
import {genMockSubscriber} from 'MockFlowableSubscriber';
import {genMockPublisher} from 'MockFlowableSubscription';
import {Single, Flowable} from 'rsocket-flowable';
import RSocketError from '../RSocketError';

jest.useFakeTimers();

Expand Down Expand Up @@ -226,6 +227,56 @@ describe('RSocketServer', () => {
expect(console.error).toHaveBeenCalled();
});

it('sends custom error code if request handler throws RSocketError', () => {
console.error = jest.fn();
const transport = genMockTransportServer();
const server = new RSocketServer({
getRequestHandler: () => {
return {
requestResponse: () => {
throw new RSocketError(1234, 'Custom Error');
},
};
},
transport,
});
server.start();
transport.mock.connect();
connection.receive.mock.publisher.onNext({
type: FRAME_TYPES.SETUP,
data: undefined,
dataMimeType: '<dataMimeType>',
flags: 0,
keepAlive: 42,
lifetime: 2017,
metadata: undefined,
metadataMimeType: '<metadataMimeType>',
resumeToken: null,
streamId: 0,
majorVersion: 1,
minorVersion: 0,
});
jest.runOnlyPendingTimers();
connection.receive.mock.publisher.onNext({
type: FRAME_TYPES.REQUEST_RESPONSE,
data: undefined,
dataMimeType: '<dataMimeType>',
flags: 0,
metadata: undefined,
metadataMimeType: '<metadataMimeType>',
streamId: 1,
});
expect(connection.sendOne.mock.calls.length).toBe(1);
expect(connection.sendOne.mock.frame).toEqual({
code: 1234,
flags: 0,
message: 'Custom Error',
streamId: 1,
type: FRAME_TYPES.ERROR,
});
expect(console.error).toHaveBeenCalled();
});

it('call subscription.cancel() for all active subscriptions', () => {
let cancelled = false;
const transport = genMockTransportServer();
Expand Down

0 comments on commit cd30156

Please sign in to comment.