Skip to content

Commit

Permalink
fix: add delay between reward (#249)
Browse files Browse the repository at this point in the history
* add delay between reward

* fix format
  • Loading branch information
rubenkristian authored Dec 22, 2022
1 parent b6d6f95 commit 32dd85e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ export class OrderFulfilledHandler
} catch (err) {
this.logger.log(err);
this.logger.log(`Forward payment failed | err -> ${err}`);
console.log(err);
}
}

callbackInsertNotificationLogging(data: NotificationDto) {
this.notificationService.insert(data);
async callbackInsertNotificationLogging(data: NotificationDto) {
await this.notificationService.insert(data);
}

async callbackSendReward(
Expand Down Expand Up @@ -202,7 +203,7 @@ export class OrderFulfilledHandler
block_number: blockNumber,
};

this.callbackInsertNotificationLogging(customerNotificationInput);
await this.callbackInsertNotificationLogging(customerNotificationInput);

// Write Logging Reward Customer Staking Request Service
const dataCustomerLoggingInput: TransactionLoggingDto = {
Expand All @@ -217,6 +218,8 @@ export class OrderFulfilledHandler
};
await this.loggingService.create(dataCustomerLoggingInput);

await this.delay(6000);

// Send reward to lab
await sendRewards(
this.substrateService.api as any,
Expand All @@ -241,7 +244,7 @@ export class OrderFulfilledHandler
block_number: blockNumber,
};

this.callbackInsertNotificationLogging(labNotificationInput);
await this.callbackInsertNotificationLogging(labNotificationInput);

// Write Logging Reward Lab
const dataLabLoggingInput: TransactionLoggingDto = {
Expand All @@ -260,4 +263,8 @@ export class OrderFulfilledHandler
private convertToDate(date: Date) {
return new Date(Number(date.toString().split(',').join('')));
}

private delay(ms: number) {
return new Promise((resolve) => setTimeout(() => resolve(true), ms));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ describe('Order Fulfilled Handler Event', () => {
let dateTimeProxyMock: MockType<DateTimeProxy>;

beforeEach(async () => {
jest
.useFakeTimers()
.setSystemTime(new Date('1970-01-01T00:00:00.001Z').getTime());
const module: TestingModule = await Test.createTestingModule({
providers: [
{
Expand Down Expand Up @@ -113,6 +110,7 @@ describe('Order Fulfilled Handler Event', () => {
const convertToDbioUnitStringSpy = jest
.spyOn(globalProviderMethods, 'convertToDbioUnitString')
.mockImplementation();

const DATE = new Date(1669649548467);
const ORDER = createMockOrder(OrderStatus.Cancelled);

Expand Down Expand Up @@ -205,6 +203,7 @@ describe('Order Fulfilled Handler Event', () => {
expect(queryServiceByIdSpy).not.toHaveBeenCalled();
expect(queryServiceRequestById).not.toHaveBeenCalled();
expect(debioConversionServiceMock.getExchange).not.toHaveBeenCalled();

expect(sendRewardsSpy).not.toHaveBeenCalled();
expect(convertToDbioUnitStringSpy).not.toHaveBeenCalled();
expect(queryServiceRequestById).not.toHaveBeenCalled();
Expand All @@ -220,6 +219,7 @@ describe('Order Fulfilled Handler Event', () => {
queryServiceByIdSpy.mockClear();
queryServiceRequestById.mockClear();
sendRewardsSpy.mockClear();

convertToDbioUnitStringSpy.mockClear();
});

Expand Down Expand Up @@ -347,7 +347,7 @@ describe('Order Fulfilled Handler Event', () => {
queryServiceInvoiceByOrderIdSpy.mockClear();
sendRewardsSpy.mockClear();
convertToDbioUnitStringSpy.mockClear();
});
}, 12000);

it('when eth address isNone true', async () => {
// Arrange
Expand All @@ -369,6 +369,7 @@ describe('Order Fulfilled Handler Event', () => {
const convertToDbioUnitStringSpy = jest
.spyOn(globalProviderMethods, 'convertToDbioUnitString')
.mockImplementation();

const DATE = new Date(1669649548467);
const ORDER = createMockOrder(OrderStatus.Cancelled);

Expand Down Expand Up @@ -477,6 +478,7 @@ describe('Order Fulfilled Handler Event', () => {
expect(queryOrderDetailByOrderIDSpy).not.toHaveBeenCalled();
expect(queryServiceByIdSpy).not.toHaveBeenCalled();
expect(queryServiceInvoiceByOrderIdSpy).not.toHaveBeenCalled();

expect(sendRewardsSpy).not.toHaveBeenCalled();
expect(convertToDbioUnitStringSpy).not.toHaveBeenCalled();
expect(queryServiceInvoiceByOrderIdSpy).not.toHaveBeenCalled();
Expand All @@ -493,7 +495,7 @@ describe('Order Fulfilled Handler Event', () => {
queryServiceInvoiceByOrderIdSpy.mockClear();
sendRewardsSpy.mockClear();
convertToDbioUnitStringSpy.mockClear();
});
}, 12000);

it('when order and service flow is not StakingRequestService', async () => {
// Arrange
Expand All @@ -515,6 +517,7 @@ describe('Order Fulfilled Handler Event', () => {
const convertToDbioUnitStringSpy = jest
.spyOn(globalProviderMethods, 'convertToDbioUnitString')
.mockImplementation();

const DATE = new Date(1669649548467);
const ORDER = createMockOrder(OrderStatus.Cancelled);

Expand Down Expand Up @@ -607,6 +610,7 @@ describe('Order Fulfilled Handler Event', () => {
expect(queryServiceByIdSpy).not.toHaveBeenCalled();
expect(queryServiceInvoiceByOrderIdSpy).not.toHaveBeenCalled();
expect(debioConversionServiceMock.getExchange).not.toHaveBeenCalled();

expect(sendRewardsSpy).not.toHaveBeenCalled();
expect(convertToDbioUnitStringSpy).not.toHaveBeenCalled();
expect(queryServiceInvoiceByOrderIdSpy).not.toHaveBeenCalled();
Expand All @@ -623,7 +627,7 @@ describe('Order Fulfilled Handler Event', () => {
queryServiceInvoiceByOrderIdSpy.mockClear();
sendRewardsSpy.mockClear();
convertToDbioUnitStringSpy.mockClear();
});
}, 12000);

it('called reward callback', async () => {
const sendRewardsSpy = jest
Expand All @@ -648,5 +652,5 @@ describe('Order Fulfilled Handler Event', () => {
expect(transactionLoggingServiceMock.create).toHaveBeenCalled();
expect(sendRewardsSpy).toHaveBeenCalledTimes(2);
expect(transactionLoggingServiceMock.create).toHaveBeenCalledTimes(2);
});
}, 12000);
});

0 comments on commit 32dd85e

Please sign in to comment.