From 12f32bc73154c8f49a67c9cccbfabf48adf0ab26 Mon Sep 17 00:00:00 2001 From: StevanFreeborn Date: Thu, 26 Jan 2023 14:44:37 -0600 Subject: [PATCH] feat: add tests for isValidPageSize and isValidPageNumber methods --- src/models/ArgumentValidator.ts | 4 +-- tests/ArgumentValidator.spec.ts | 64 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/models/ArgumentValidator.ts b/src/models/ArgumentValidator.ts index 77f0a7d..45585af 100644 --- a/src/models/ArgumentValidator.ts +++ b/src/models/ArgumentValidator.ts @@ -31,7 +31,7 @@ export class ArgumentValidator { * @returns {boolean} - True if the value is a valid page size; otherwise, false. * @remarks - A valid page size is a number greater than 0 and less than or equal to 1000. */ - public static isValidPageSize(value: number): boolean { + public static isValidPageSize(value: number | null | undefined): boolean { return value > 0 && value <= 1000; } @@ -40,7 +40,7 @@ export class ArgumentValidator { * @returns {boolean} - True if the value is a valid page number; otherwise, false. * @remarks - A valid page number is a number greater than 0. */ - public static isValidPageNumber(value: number): boolean { + public static isValidPageNumber(value: number | null | undefined): boolean { return value > 0; } } diff --git a/tests/ArgumentValidator.spec.ts b/tests/ArgumentValidator.spec.ts index 2e9dece..786800a 100644 --- a/tests/ArgumentValidator.spec.ts +++ b/tests/ArgumentValidator.spec.ts @@ -169,4 +169,68 @@ describe('ArgumentValidator', function () { expect(ArgumentValidator.isValidUrl('https://www.google.com')).to.be.true; }); }); + + describe('isValidPageSize', function () { + it('should be defined', function () { + expect(ArgumentValidator.isValidPageSize).to.not.be.undefined; + }); + + it('should have 1 parameter of type number', function () { + expect(ArgumentValidator.isValidPageSize).to.have.lengthOf(1); + }); + + it('should return false when the value is null', function () { + expect(ArgumentValidator.isValidPageSize(null)).to.be.false; + }); + + it('should return false when the value is undefined', function () { + expect(ArgumentValidator.isValidPageSize(undefined)).to.be.false; + }); + + it('should return false when the value is greater than 1000', function (){ + expect(ArgumentValidator.isValidPageSize(1001)).to.be.false; + }); + + it('should return false when the value is less than 1', function (){ + expect(ArgumentValidator.isValidPageSize(0)).to.be.false; + }); + + it('should return true when the value is 1', function (){ + expect(ArgumentValidator.isValidPageSize(1)).to.be.true; + }); + + it('should return true when the value is 1000', function (){ + expect(ArgumentValidator.isValidPageSize(1000)).to.be.true; + }); + + it('should return true when the value is 500', function (){ + expect(ArgumentValidator.isValidPageSize(500)).to.be.true; + }); + }); + + describe('isValidPageNumber', function () { + it('should be defined', function () { + expect(ArgumentValidator.isValidPageNumber).to.not.be.undefined; + }); + + it('should have 1 parameter of type number', function () { + expect(ArgumentValidator.isValidPageNumber).to.have.lengthOf(1); + }); + + it('should return false when the value is null', function () { + expect(ArgumentValidator.isValidPageNumber(null)).to.be.false; + }); + + it('should return false when the value is undefined', function () { + expect(ArgumentValidator.isValidPageNumber(undefined)).to.be.false; + }); + + it('should return false when the value is less than 1', function (){ + expect(ArgumentValidator.isValidPageNumber(0)).to.be.false; + }); + + it('should return true when the value is 1', function (){ + expect(ArgumentValidator.isValidPageNumber(1)).to.be.true; + }); + }); });