From 52edb3aa8425777741cffc8fd2ca1f9bb3d06ca3 Mon Sep 17 00:00:00 2001 From: okjodom Date: Sat, 2 Nov 2024 15:29:19 +0300 Subject: [PATCH] feat: list offramp swap transactions --- apps/api/src/swap/swap.controller.spec.ts | 7 +++++++ apps/api/src/swap/swap.controller.ts | 23 +++++++++++++++++++-- apps/api/src/swap/swap.service.spec.ts | 25 ++++++++++++++++++++--- apps/api/src/swap/swap.service.ts | 4 ++-- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/apps/api/src/swap/swap.controller.spec.ts b/apps/api/src/swap/swap.controller.spec.ts index 4201cbc..a15f256 100644 --- a/apps/api/src/swap/swap.controller.spec.ts +++ b/apps/api/src/swap/swap.controller.spec.ts @@ -139,4 +139,11 @@ describe('SwapController', () => { expect(swapService.findOfframpTransaction).toHaveBeenCalled(); }); }); + + describe('getOfframpTransactions', () => { + it('should call swapService.getOfframpTransactions', () => { + controller.getOfframpTransactions(); + expect(swapService.getOfframpTransactions).toHaveBeenCalled(); + }); + }); }); diff --git a/apps/api/src/swap/swap.controller.ts b/apps/api/src/swap/swap.controller.ts index 9cb0e59..d351e92 100644 --- a/apps/api/src/swap/swap.controller.ts +++ b/apps/api/src/swap/swap.controller.ts @@ -136,8 +136,27 @@ export class SwapController { } @Get('offramp/all') - getOfframpTransactions() { - return this.swapService.getOfframpTransactions(); + @ApiOperation({ summary: 'List offramp swaps' }) + @ApiQuery({ + name: 'page', + example: '?page=0', + type: ListSwapsDto['page'], + required: false, + }) + @ApiQuery({ + name: 'size', + example: '?size=100', + type: ListSwapsDto['size'], + required: false, + }) + getOfframpTransactions( + @Query('page') page: number = 0, + @Query('size') size: number = 100, + ) { + return this.swapService.getOfframpTransactions({ + page, + size, + }); } @Post('webhook') diff --git a/apps/api/src/swap/swap.service.spec.ts b/apps/api/src/swap/swap.service.spec.ts index d0b16d0..ffa7ec5 100644 --- a/apps/api/src/swap/swap.service.spec.ts +++ b/apps/api/src/swap/swap.service.spec.ts @@ -83,6 +83,20 @@ describe('SwapService', () => { status: 'PENDING', }; }), + listOfframpSwaps: jest.fn().mockImplementation(async () => { + return { + swaps: [ + { + id: mock_id, + rate: (1 / mock_btc_kes).toString(), + status: 'PENDING', + }, + ], + page: 0, + size: 10, + pages: 2, + }; + }), }; }); @@ -169,7 +183,7 @@ describe('SwapService', () => { }); describe('getOnrampTransactions', () => { - it('should return status 200', () => { + it('can get a paginated list of onramp swaps', () => { expect( swapService.getOnrampTransactions({ page: 0, @@ -241,8 +255,13 @@ describe('SwapService', () => { }); describe('getOfframpTransactions', () => { - it('should return status 200', () => { - expect(swapService.getOfframpTransactions()).toEqual({ status: 200 }); + it('can get a paginated list of offramp swaps', () => { + expect( + swapService.getOfframpTransactions({ + page: 0, + size: 10, + }), + ).toBeDefined(); }); }); }); diff --git a/apps/api/src/swap/swap.service.ts b/apps/api/src/swap/swap.service.ts index a41c04a..4bd2bb5 100644 --- a/apps/api/src/swap/swap.service.ts +++ b/apps/api/src/swap/swap.service.ts @@ -56,7 +56,7 @@ export class SwapService implements OnModuleInit { return this.client.findOfframpSwap(req); } - getOfframpTransactions() { - return { status: 200 }; + getOfframpTransactions(req: ListSwapsDto) { + return this.client.listOfframpSwaps(req); } }