feat: add tests for isValidPageSize and isValidPageNumber methods

This commit is contained in:
StevanFreeborn
2023-01-26 14:44:37 -06:00
parent 7cacd4521f
commit 12f32bc731
2 changed files with 66 additions and 2 deletions
+2 -2
View File
@@ -31,7 +31,7 @@ export class ArgumentValidator {
* @returns {boolean} - True if the value is a valid page size; otherwise, false. * @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. * @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; 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. * @returns {boolean} - True if the value is a valid page number; otherwise, false.
* @remarks - A valid page number is a number greater than 0. * @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; return value > 0;
} }
} }
+64
View File
@@ -169,4 +169,68 @@ describe('ArgumentValidator', function () {
expect(ArgumentValidator.isValidUrl('https://www.google.com')).to.be.true; 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;
});
});
}); });