From d176739a53ff6f7ebb217f04c8595f7f76901448 Mon Sep 17 00:00:00 2001 From: Krish Date: Wed, 28 May 2025 18:39:11 +0530 Subject: [PATCH 1/2] fix(nodejs-hal-tools): Correct next page logic in calculateNextPage utility * Fix: correct next page logic in calculateNextPage utility * test: enhance tests for calculateNextPage utility (#431) --- libs/javascript/pagination/src/hal-format.helper.spec.ts | 8 ++++++++ libs/javascript/pagination/src/hal-format.helper.ts | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/javascript/pagination/src/hal-format.helper.spec.ts b/libs/javascript/pagination/src/hal-format.helper.spec.ts index 4ee8f6e1..e8693bf1 100644 --- a/libs/javascript/pagination/src/hal-format.helper.spec.ts +++ b/libs/javascript/pagination/src/hal-format.helper.spec.ts @@ -51,6 +51,14 @@ describe('HAL Format Tools', () => { it('should return 1 if there is only one page', () => { expect(calculateNextPage(1, 1)).toBe(1); }); + + it('should handle invalid input gracefully: currentPage > totalPages', () => { + expect(calculateNextPage(3, 5)).toBe(3); + }); + + it('should handle 0 as current page', () => { + expect(calculateNextPage(5, 0)).toBe(1); + }); }); describe('createHalLinks', () => { diff --git a/libs/javascript/pagination/src/hal-format.helper.ts b/libs/javascript/pagination/src/hal-format.helper.ts index 834e6436..3bbd9673 100644 --- a/libs/javascript/pagination/src/hal-format.helper.ts +++ b/libs/javascript/pagination/src/hal-format.helper.ts @@ -41,9 +41,10 @@ export function calculatePagination( * @param currentPage */ export function calculateNextPage(totalPages: number, currentPage: number): number { - return currentPage === totalPages ? currentPage : currentPage + 1; + return currentPage < totalPages ? currentPage + 1 : currentPage; } + /** * Create the HAL-format links to self, first-, last- & next-page. * @param path From 2aa00158cb27cca1b85ee5a979d4cbcd3f956fa3 Mon Sep 17 00:00:00 2001 From: Iben Van de Veire Date: Wed, 28 May 2025 15:13:32 +0200 Subject: [PATCH 2/2] build(nodejs-hal-tools):v2.0.1 --- libs/javascript/pagination/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/javascript/pagination/package.json b/libs/javascript/pagination/package.json index 96d96365..91c03bad 100644 --- a/libs/javascript/pagination/package.json +++ b/libs/javascript/pagination/package.json @@ -1,6 +1,6 @@ { "name": "@studiohyperdrive/nodejs-hal-tools", - "version": "2.0.0", + "version": "2.0.1", "description": "A NodeJs based approach to pagination based on the HAL standards.", "keywords": [ "pagination",