From 92bf5e9177af62463cf9b0d58346b98c4871d631 Mon Sep 17 00:00:00 2001 From: Roman Petriv Date: Wed, 6 Mar 2024 13:54:41 +0200 Subject: [PATCH] test: add tests --- .../src/address/address.controller.spec.ts | 25 ++++++++++++++++--- packages/api/test/address.e2e-spec.ts | 17 +++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/packages/api/src/address/address.controller.spec.ts b/packages/api/src/address/address.controller.spec.ts index e215f6c378..35586a0f8a 100644 --- a/packages/api/src/address/address.controller.spec.ts +++ b/packages/api/src/address/address.controller.spec.ts @@ -12,7 +12,7 @@ import { Token } from "../token/token.entity"; import { PagingOptionsWithMaxItemsLimitDto } from "../common/dtos"; import { AddressType } from "./dtos/baseAddress.dto"; import { TransferService } from "../transfer/transfer.service"; -import { Transfer } from "../transfer/transfer.entity"; +import { Transfer, TransferType } from "../transfer/transfer.entity"; jest.mock("../common/utils", () => ({ ...jest.requireActual("../common/utils"), @@ -286,8 +286,8 @@ describe("AddressController", () => { (transferServiceMock.findAll as jest.Mock).mockResolvedValueOnce(transfers); }); - it("queries transfers with the specified options", async () => { - await controller.getAddressTransfers(address, listFilterOptions, pagingOptions); + it("queries transfers with the specified options when no filters provided", async () => { + await controller.getAddressTransfers(address, {}, listFilterOptions, pagingOptions); expect(transferServiceMock.findAll).toHaveBeenCalledTimes(1); expect(transferServiceMock.findAll).toHaveBeenCalledWith( { @@ -303,8 +303,25 @@ describe("AddressController", () => { ); }); + it("queries transfers with the specified options when filters are provided", async () => { + await controller.getAddressTransfers(address, { type: TransferType.Transfer }, listFilterOptions, pagingOptions); + expect(transferServiceMock.findAll).toHaveBeenCalledTimes(1); + expect(transferServiceMock.findAll).toHaveBeenCalledWith( + { + address, + type: TransferType.Transfer, + timestamp: "timestamp", + }, + { + filterOptions: { type: TransferType.Transfer, ...listFilterOptions }, + ...pagingOptions, + route: `address/${address}/transfers`, + } + ); + }); + it("returns the transfers", async () => { - const result = await controller.getAddressTransfers(address, listFilterOptions, pagingOptions); + const result = await controller.getAddressTransfers(address, {}, listFilterOptions, pagingOptions); expect(result).toBe(transfers); }); }); diff --git a/packages/api/test/address.e2e-spec.ts b/packages/api/test/address.e2e-spec.ts index 0c51412dcc..ecb56ccaa5 100644 --- a/packages/api/test/address.e2e-spec.ts +++ b/packages/api/test/address.e2e-spec.ts @@ -342,6 +342,7 @@ describe("AddressController (e2e)", () => { tokenAddress: transferSpec.tokenAddress, blockNumber: transferSpec.blockNumber, timestamp: transferSpec.timestamp, + type: transferSpec.type, tokenType: transferSpec.tokenType, isFeeOrRefund: transferSpec.isFeeOrRefund, logIndex: transferSpec.logIndex, @@ -1167,6 +1168,22 @@ describe("AddressController (e2e)", () => { ); }); + it("returns HTTP 200 and address transfers for the specified transfer type", () => { + return request(app.getHttpServer()) + .get("/address/0x91d0a23f34e535e44df8ba84c53a0945cf0eeb67/transfers?type=withdrawal") + .expect(200) + .expect((res) => + expect(res.body.meta).toMatchObject({ + currentPage: 1, + itemCount: 5, + itemsPerPage: 10, + totalItems: 5, + totalPages: 1, + }) + ) + .expect((res) => expect(res.body.items[0].type).toBe(TransferType.Withdrawal)); + }); + it("returns HTTP 200 and address transfers for the specified paging configuration", () => { return request(app.getHttpServer()) .get(