Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenkristian committed Nov 16, 2022
1 parent 14dfc7a commit 426e2da
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class OrderFulfilledHandler
this.logger.log(`labEthAddress: ${labEthAddress}`);
this.logger.log(`amountToForward: ${amountToForward}`);
} catch (err) {
console.log(err);
this.logger.log(err);
this.logger.log(`Forward payment failed | err -> ${err}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ describe('Order Fulfilled Handler Event', () => {
const convertToDbioUnitStringSpy = jest
.spyOn(globalProviderMethods, 'convertToDbioUnitString')
.mockImplementation();
const conversionFromTo = jest
.spyOn(debioConversionServiceMock, 'getExchangeFromTo')
.mockReturnValue({ conversion: 1 });
const DATE = new Date();
const ORDER = createMockOrder(OrderStatus.Cancelled, DATE);

Expand Down Expand Up @@ -607,26 +610,24 @@ describe('Order Fulfilled Handler Event', () => {
.spyOn(rewardCommand, 'sendRewards')
.mockImplementation();

const convertToDbioUnitStringSpy = jest
.spyOn(globalProviderMethods, 'convertToDbioUnitString')
.mockImplementation();
debioConversionServiceMock.getExchangeFromTo.mockReturnValue({
conversion: 1,
});

const DATE = new Date();
const ORDER = createMockOrder(OrderStatus.Cancelled, DATE);
const PRICE = 1;
const BLOCKNUMBER = '1';

await orderFulfilledHandler.callbackSendReward(
new Order(ORDER),
new Order(ORDER.toHuman()),
PRICE,
BLOCKNUMBER,
);

expect(sendRewardsSpy).toHaveBeenCalled();
expect(convertToDbioUnitStringSpy).toHaveBeenCalled();
expect(transactionLoggingServiceMock.create).toHaveBeenCalled();
expect(sendRewardsSpy).toHaveBeenCalledTimes(2);
expect(convertToDbioUnitStringSpy).toHaveBeenCalledTimes(2);
expect(transactionLoggingServiceMock.create).toHaveBeenCalledTimes(2);
});
});
1 change: 1 addition & 0 deletions test/unit/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const ethereumServiceMockFactory: () => MockType<EthereumService> =
export const debioConversionServiceMockFactory: () => MockType<DebioConversionService> =
jest.fn(() => ({
getExchange: jest.fn(),
getExchangeFromTo: jest.fn(),
}));

export const transactionLoggingServiceMockFactory: () => MockType<TransactionLoggingService> =
Expand Down

0 comments on commit 426e2da

Please sign in to comment.