From 9e4d45aa5bdc88a7c619dd8a1d6d956051296f12 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 4 Sep 2020 17:18:32 +0100 Subject: [PATCH] Fixed #657 - Removed totalPage and TotalEntries from pagination --- package-lock.json | 8 ++++---- package.json | 2 +- src/infrastructure/Http.ts | 2 -- src/infrastructure/Page.ts | 12 ++---------- test/infrastructure/AccountHttp.spec.ts | 2 -- test/infrastructure/BlockHttp.spec.ts | 2 -- test/infrastructure/MetadataHttp.spec.ts | 2 -- test/infrastructure/MosaicHttp.spec.ts | 2 -- test/infrastructure/NamespaceHttp.spec.ts | 2 -- test/infrastructure/Page.spec.ts | 16 +++++++--------- test/infrastructure/ReceiptHttp.spec.ts | 6 ------ test/infrastructure/TransactionHttp.spec.ts | 8 -------- .../streamer/PaginationStreamerTestHelper.ts | 2 +- test/service/AccountService.spec.ts | 4 ++-- test/service/MetadataTransactionservice.spec.ts | 6 +++--- 15 files changed, 20 insertions(+), 56 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7cec31efd2..22fbe5c12e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5135,7 +5135,7 @@ }, "which-module": { "version": "2.0.0", - "resolved": false, + "resolved": "", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", "dev": true }, @@ -6611,9 +6611,9 @@ } }, "symbol-openapi-typescript-fetch-client": { - "version": "0.9.6", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.9.6.tgz", - "integrity": "sha512-ZZtR031IBkYfiG0bR26vGckKmUrJzY9sggXMusrqloxweNovtzf7Aqpx7nNEpCJdMNzwv+E0V8mYBwxgFuiMfg==" + "version": "0.9.7-SNAPSHOT.202009041234", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-fetch-client/-/symbol-openapi-typescript-fetch-client-0.9.7-SNAPSHOT.202009041234.tgz", + "integrity": "sha512-r16MHZdPMQsYr6gVgcyDyQiSbu9KEhMeTx5zwly8jvV7lMjLbGdOKQt3y80P2fFPbvPZ5IhCFYJTu2saohLpkg==" }, "table": { "version": "5.4.6", diff --git a/package.json b/package.json index 309dc3d8bc..be6524aba2 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-fetch-client": "0.9.6", + "symbol-openapi-typescript-fetch-client": "0.9.7-SNAPSHOT.202009041234", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" diff --git a/src/infrastructure/Http.ts b/src/infrastructure/Http.ts index 8674602a65..f10d4fea3c 100644 --- a/src/infrastructure/Http.ts +++ b/src/infrastructure/Http.ts @@ -139,8 +139,6 @@ export abstract class Http { data.map((d) => mapper(d, networkType)), pagination?.pageNumber, pagination?.pageSize, - pagination?.totalEntries, - pagination?.totalPages, ); } } diff --git a/src/infrastructure/Page.ts b/src/infrastructure/Page.ts index 441db1f7c9..338ec7d17e 100644 --- a/src/infrastructure/Page.ts +++ b/src/infrastructure/Page.ts @@ -27,16 +27,8 @@ export class Page { * @param data the page data * @param pageNumber the current page number starting from 1. * @param pageSize the page size. - * @param totalEntries the total entries. - * @param totalPages the total pages for the given criteria. */ - constructor( - public readonly data: T[], - public readonly pageNumber: number, - public readonly pageSize: number, - public readonly totalEntries: number, - public readonly totalPages: number, - ) { - this.isLastPage = this.pageNumber >= this.totalPages; + constructor(public readonly data: T[], public readonly pageNumber: number, public readonly pageSize: number) { + this.isLastPage = !this.data.length || this.pageSize > this.data.length; } } diff --git a/test/infrastructure/AccountHttp.spec.ts b/test/infrastructure/AccountHttp.spec.ts index 86a6c4d652..64d291b20c 100644 --- a/test/infrastructure/AccountHttp.spec.ts +++ b/test/infrastructure/AccountHttp.spec.ts @@ -129,8 +129,6 @@ describe('AccountHttp', () => { const pagination = {} as Pagination; pagination.pageNumber = 1; pagination.pageSize = 1; - pagination.totalEntries = 1; - pagination.totalPages = 1; const body = {} as AccountPage; body.data = [accountInfoDto]; diff --git a/test/infrastructure/BlockHttp.spec.ts b/test/infrastructure/BlockHttp.spec.ts index 9efb884bd6..5e223b47e5 100644 --- a/test/infrastructure/BlockHttp.spec.ts +++ b/test/infrastructure/BlockHttp.spec.ts @@ -109,8 +109,6 @@ describe('BlockHttp', () => { const pagination = {} as Pagination; pagination.pageNumber = 1; pagination.pageSize = 1; - pagination.totalEntries = 1; - pagination.totalPages = 1; const body = {} as BlockPage; body.data = [blockInfoDto]; diff --git a/test/infrastructure/MetadataHttp.spec.ts b/test/infrastructure/MetadataHttp.spec.ts index 8d9050041d..62ef2d0e55 100644 --- a/test/infrastructure/MetadataHttp.spec.ts +++ b/test/infrastructure/MetadataHttp.spec.ts @@ -49,8 +49,6 @@ describe('MetadataHttp', () => { const pagination = {} as Pagination; pagination.pageNumber = 1; pagination.pageSize = 1; - pagination.totalEntries = 1; - pagination.totalPages = 1; const metadataDTOMosaic = {} as MetadataInfoDTO; metadataDTOMosaic.id = 'aaa'; diff --git a/test/infrastructure/MosaicHttp.spec.ts b/test/infrastructure/MosaicHttp.spec.ts index e577e1c8e0..026db01607 100644 --- a/test/infrastructure/MosaicHttp.spec.ts +++ b/test/infrastructure/MosaicHttp.spec.ts @@ -99,8 +99,6 @@ describe('MosaicHttp', () => { const pagination = {} as Pagination; pagination.pageNumber = 1; pagination.pageSize = 1; - pagination.totalEntries = 1; - pagination.totalPages = 1; const body = {} as MosaicPage; body.data = [mosaicInfoDto]; diff --git a/test/infrastructure/NamespaceHttp.spec.ts b/test/infrastructure/NamespaceHttp.spec.ts index 9e3d5d260d..e7914bfca6 100644 --- a/test/infrastructure/NamespaceHttp.spec.ts +++ b/test/infrastructure/NamespaceHttp.spec.ts @@ -208,8 +208,6 @@ describe('NamespaceHttp', () => { const pagination = {} as Pagination; pagination.pageNumber = 1; pagination.pageSize = 1; - pagination.totalEntries = 1; - pagination.totalPages = 1; const body = {} as NamespacePage; body.data = [namespaceInfoDto]; diff --git a/test/infrastructure/Page.spec.ts b/test/infrastructure/Page.spec.ts index 0894284b74..56f08b6d9d 100644 --- a/test/infrastructure/Page.spec.ts +++ b/test/infrastructure/Page.spec.ts @@ -30,22 +30,20 @@ describe('Page', () => { [TransferTransaction.create(Deadline.create(), account.address, [], PlainMessage.create(''), NetworkType.TEST_NET)], 1, 1, - 1, - 1, ); expect(page.data.length).to.be.equal(1); expect(page.pageNumber).to.be.equal(1); expect(page.pageSize).to.be.equal(1); - expect(page.totalEntries).to.be.equal(1); - expect(page.isLastPage).to.be.true; + expect(page.isLastPage).to.be.false; page = new Page( [TransferTransaction.create(Deadline.create(), account.address, [], PlainMessage.create(''), NetworkType.TEST_NET)], - 1, - 1, - 1, - 3, + 2, + 2, ); - expect(page.isLastPage).to.be.false; + expect(page.isLastPage).to.be.true; + + page = new Page([], 2, 2); + expect(page.isLastPage).to.be.true; }); }); diff --git a/test/infrastructure/ReceiptHttp.spec.ts b/test/infrastructure/ReceiptHttp.spec.ts index 07210e8b62..51ea92fd87 100644 --- a/test/infrastructure/ReceiptHttp.spec.ts +++ b/test/infrastructure/ReceiptHttp.spec.ts @@ -77,8 +77,6 @@ describe('ReceiptHttp', () => { const pagination = {} as Pagination; pagination.pageNumber = 1; pagination.pageSize = 20; - pagination.totalEntries = 1; - pagination.totalPages = 1; resolutionPage.pagination = pagination; when(receiptRoutesApi.searchMosaicResolutionStatements('1', undefined, undefined, undefined, undefined)).thenReturn( @@ -118,8 +116,6 @@ describe('ReceiptHttp', () => { const pagination = {} as Pagination; pagination.pageNumber = 1; pagination.pageSize = 20; - pagination.totalEntries = 1; - pagination.totalPages = 1; resolutionPage.pagination = pagination; when(receiptRoutesApi.searchAddressResolutionStatements('1', undefined, undefined, undefined, undefined)).thenReturn( @@ -161,8 +157,6 @@ describe('ReceiptHttp', () => { const pagination = {} as Pagination; pagination.pageNumber = 1; pagination.pageSize = 20; - pagination.totalEntries = 1; - pagination.totalPages = 1; resolutionPage.pagination = pagination; when( diff --git a/test/infrastructure/TransactionHttp.spec.ts b/test/infrastructure/TransactionHttp.spec.ts index 86283ac63d..fb3a221618 100644 --- a/test/infrastructure/TransactionHttp.spec.ts +++ b/test/infrastructure/TransactionHttp.spec.ts @@ -94,8 +94,6 @@ describe('TransactionHttp', () => { const paginationDto = {} as Pagination; paginationDto.pageNumber = 1; paginationDto.pageSize = 1; - paginationDto.totalEntries = 1; - paginationDto.totalPages = 1; const transactionInfoDto = {} as TransactionInfoDTO; const metaDto = {} as TransactionMetaDTO; @@ -177,8 +175,6 @@ describe('TransactionHttp', () => { expect(transactions.pageNumber).to.be.equal(1); expect(transactions.pageSize).to.be.equal(1); - expect(transactions.totalEntries).to.be.equal(1); - expect(transactions.totalPages).to.be.equal(1); transactions = await transactionHttp.search({ group: TransactionGroup.Unconfirmed, address: account.address }).toPromise(); @@ -192,8 +188,6 @@ describe('TransactionHttp', () => { expect(transactions.pageNumber).to.be.equal(1); expect(transactions.pageSize).to.be.equal(1); - expect(transactions.totalEntries).to.be.equal(1); - expect(transactions.totalPages).to.be.equal(1); transactions = await transactionHttp.search({ group: TransactionGroup.Partial, address: account.address }).toPromise(); @@ -207,8 +201,6 @@ describe('TransactionHttp', () => { expect(transactions.pageNumber).to.be.equal(1); expect(transactions.pageSize).to.be.equal(1); - expect(transactions.totalEntries).to.be.equal(1); - expect(transactions.totalPages).to.be.equal(1); }); it('Test getTransaction method', async () => { diff --git a/test/infrastructure/streamer/PaginationStreamerTestHelper.ts b/test/infrastructure/streamer/PaginationStreamerTestHelper.ts index 9a8113afe6..a48ae8885d 100644 --- a/test/infrastructure/streamer/PaginationStreamerTestHelper.ts +++ b/test/infrastructure/streamer/PaginationStreamerTestHelper.ts @@ -68,6 +68,6 @@ export class PaginationStreamerTestHelper { partitions.push(infos.slice(i, i + pageSize)); } let pageNumber = 0; - return partitions.map((pageData) => of(new Page(pageData, ++pageNumber, pageSize, infos.length, partitions.length))); + return partitions.map((pageData) => of(new Page(pageData, ++pageNumber, pageSize))); } } diff --git a/test/service/AccountService.spec.ts b/test/service/AccountService.spec.ts index 97f130fc05..6c93187305 100644 --- a/test/service/AccountService.spec.ts +++ b/test/service/AccountService.spec.ts @@ -133,10 +133,10 @@ describe('AccountService', () => { pageNumber: 1, }), ), - ).thenReturn(observableOf(new Page(mockNamespaceInfo(), 1, 20, 3, 1))); + ).thenReturn(observableOf(new Page(mockNamespaceInfo(), 1, 20))); when(mockNamespaceRepository.search(deepEqual({ ownerAddress: account.address, pageNumber: 1 }))).thenReturn( - observableOf(new Page(mockNamespaceInfo(), 1, 20, 3, 1)), + observableOf(new Page(mockNamespaceInfo(), 1, 20)), ); when(mockNamespaceRepository.getNamespacesNames(deepEqual([NetworkCurrencyLocal.NAMESPACE_ID]))).thenReturn( diff --git a/test/service/MetadataTransactionservice.spec.ts b/test/service/MetadataTransactionservice.spec.ts index 93974c9ca9..d3ec41a946 100644 --- a/test/service/MetadataTransactionservice.spec.ts +++ b/test/service/MetadataTransactionservice.spec.ts @@ -80,7 +80,7 @@ describe('MetadataTransactionService', () => { metadataType: MetadataType.Account, }), ), - ).thenReturn(observableOf(new Page([mockMetadata(MetadataType.Account)], 1, 20, 1, 1))); + ).thenReturn(observableOf(new Page([mockMetadata(MetadataType.Account)], 1, 20))); when( mockMetadataRepository.search( @@ -91,7 +91,7 @@ describe('MetadataTransactionService', () => { metadataType: MetadataType.Mosaic, }), ), - ).thenReturn(observableOf(new Page([mockMetadata(MetadataType.Mosaic)], 1, 20, 1, 1))); + ).thenReturn(observableOf(new Page([mockMetadata(MetadataType.Mosaic)], 1, 20))); when( mockMetadataRepository.search( @@ -102,7 +102,7 @@ describe('MetadataTransactionService', () => { metadataType: MetadataType.Namespace, }), ), - ).thenReturn(observableOf(new Page([mockMetadata(MetadataType.Namespace)], 1, 20, 1, 1))); + ).thenReturn(observableOf(new Page([mockMetadata(MetadataType.Namespace)], 1, 20))); const metadataRepository = instance(mockMetadataRepository); metadataTransactionService = new MetadataTransactionService(metadataRepository);