Skip to content

Commit

Permalink
Pass the caught error to the callback
Browse files Browse the repository at this point in the history
  • Loading branch information
ishantiw committed Jul 13, 2020
1 parent f610afa commit 593e74b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Expand Up @@ -83,6 +83,6 @@ export const getPeers = (channel: BaseChannel) => async (

res.status(200).send(peers);
} catch (err) {
next();
next(err);
}
};
Expand Up @@ -64,6 +64,25 @@ describe('Peers endpoint', () => {
expect(status).toBe(200);
});

it('should throw 500 error when channel.invoke fails', async () => {
// Arrange
app['_channel'].invoke = jest.fn();
// Mock channel invoke only when app:getConnectedPeers is called
when(app['_channel'].invoke)
.calledWith('app:getConnectedPeers')
.mockRejectedValue(new Error('test') as never);
const { response, status } = await callNetwork(axios.get(getURL('/api/peers')));
// Assert
expect(status).toBe(500);
expect(response).toEqual({
errors: [
{
message: 'test',
},
],
});
});

it('should respond with 400 and error message when passed incorrect state value', async () => {
const { response, status } = await callNetwork(axios.get(getURL('/api/peers?state=xxx')));
// Assert
Expand Down

0 comments on commit 593e74b

Please sign in to comment.