Skip to content

Commit

Permalink
LogSubscriptionTest improved
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Furter committed Apr 26, 2019
1 parent b9fe454 commit 3b16473
Showing 1 changed file with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('LogSubscriptionTest', () => {
socketProviderMock.on = jest.fn((subscriptionId, callback) => {
expect(subscriptionId).toEqual('MY_ID');

callback(false, 'SUBSCRIPTION_ITEM');
callback('SUBSCRIPTION_ITEM');
});

moduleInstanceMock.currentProvider = socketProviderMock;
Expand Down Expand Up @@ -121,6 +121,32 @@ describe('LogSubscriptionTest', () => {
).toBeInstanceOf(LogSubscription);
});

it('calls subscribe executes GetPastLogsMethod and emits the error event', (done) => {
formatters.inputLogFormatter.mockReturnValueOnce({});

getPastLogsMethodMock.execute = jest.fn(() => {
return Promise.reject(new Error('ERROR'));
});

logSubscription.options.fromBlock = 0;

const subscription = logSubscription.subscribe();

subscription.on('error', (error) => {
expect(error).toEqual(new Error('ERROR'));

expect(formatters.inputLogFormatter).toHaveBeenCalledWith(logSubscription.options);

expect(getPastLogsMethodMock.parameters).toEqual([{}]);

expect(getPastLogsMethodMock.execute).toHaveBeenCalled();

expect(subscription).toBeInstanceOf(LogSubscription);

done();
});
});

it('calls subscribe and calls the callback once', (done) => {
formatters.outputLogFormatter.mockReturnValueOnce('ITEM');

Expand All @@ -137,7 +163,7 @@ describe('LogSubscriptionTest', () => {
socketProviderMock.on = jest.fn((subscriptionId, callback) => {
expect(subscriptionId).toEqual('MY_ID');

callback(false, 'SUBSCRIPTION_ITEM');
callback('SUBSCRIPTION_ITEM');
});

moduleInstanceMock.currentProvider = socketProviderMock;
Expand Down

0 comments on commit 3b16473

Please sign in to comment.