feat: add tests for isValidPageSize and isValidPageNumber methods
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user