What’s the postman code for validating and testing phone number ranges for example you want testers to only use numbers ranging from 0789999000 to 0789999999?
I used this but failed.
pm.test(“Verifying test number range limit”, function(){
pm.expect(response.APIStatus.subscriberid).to.be.above(256789999000);
})
The following is another option, but please note, you need to strip the zero from the beginning for it to work properly. It will drop the zero for most, but if the number starts 08 or 09, it will be treated differently which may cause undesired effects.
let telNumber = "0789999001";
pm.test("Verifying test number range limit", function () {
pm.expect(parseInt(telNumber)).to.be.within(parseInt("0789999000"), parseInt("0789999999"));
});
As your numbers start with a 07, the 0 will get dropped when you parse it to an integer.
let customerId = "256789999001";
pm.test("Verifying test MSISDN range limits", function () {
pm.expect(parseInt(customerId)).to.be.within(parseInt(256789999000), parseInt(256789999033));
});
It's still passing a success even with a number outside the range

What am I doing wrong?
let customerId = "256789999001";
pm.test("Verifying test MSISDN range limits", function () {
pm.expect(parseInt(customerId)).to.be.within(parseInt(256789999000), parseInt(256789999033));
});
But I still received success whether within or outside the range.
let customerId = "256789998000";
pm.test("Verifying test MSISDN range limits", function () {
pm.expect(parseInt(customerId)).to.be.within(parseInt(256789999000), parseInt(256789999033));
});
@mdjones my target is to limit anyone else from using a customerId [in the request body], that is outside the range.
That means I’ll be testing the ‘customerId’ on the side of ‘request’ and not 'response 'and if any user puts one that is outside, they receive an error.
I don’t want to specify the numbers in the test script/code but the condition should ensure that ‘any’ numbers used must be within range.
let customerIds = ["256789998999","256789999000","256789999001", "256789999032","256789999033","256789999034","256789999077"];
let regex = /^256(7[7-8]|4[1-9])[0-9]{7}$/;
customerIds.forEach(customerId =>
pm.test(`VERIFY CORRECT MSISDN - Range ${customerId}`, function(){
pm.expect(customerId).to.match(regex)
})
);
Not exactly sure what your regex is supposed to be doing, but its not checking if the numbers are between 256789999000 and 256789999033.
All of the test data is passing.
^ Matches the beginning of a the string
match a 2 character
match a 5 character
match a 6 character
(match 7 + range 7-8) or (match 4 + range 1-9)
match range 0-9
Quantifier - match 7 of the preceding token (which was range 0-9)
$ matches the end of the string
What am trying to do is this. With this API am testing, testers have a strict range of allowed test numbers they’re to use for testing to limit them from committing fraud. When you use a wrong number, your api response body doesn’t have a success and the test results also fail.
This below is working. The test numbers must fulfil this: 1st four = 2567, next can either be a 7 or 8, next 4 digits are 9s and the last three range from 000 to 999.
//Allowed Test MSISDN Range
var validRange;
pm.test("Allowed Test MSISDN Range", function(){
var bdyraw = JSON.parse(pm.request.body.raw);
var xyz = bdyraw.customerId;
var regex = /^256(7[7-8])[9-9]{4}|[0-9]{3}$/;
var check = xyz.match(regex);
console.log(check);
if(check.index!=0){
validRange= false;
pm.expect(validRange).to.eql(true)
}else{
validRange= true;
pm.expect(validRange).to.eql(true)
}
})
I would recommend the same as any other test, that you boundary test the logic.
Make sure it fails where it should.
I’ve just included your updated regex and its not failing if the first four digits are 2566 or 2568. I haven’t even got around to testing the rest of the regex.
My recommendation when testing regex is to do it back to front. Test the last elements first and work your way to the beginning elements.
let customerIds = [
"256779999000", // pass
"256679999000", // fail
"256879999000" // fail
];
let regex = /^256(7[7-8])[9-9]{4}|[0-9]{3}$/;
customerIds.forEach(customerId =>
pm.test(`VERIFY CORRECT MSISDN - Range ${customerId}`, function(){
pm.expect(customerId).to.match(regex)
})
);
Am not specifying any customerIds because I want testers be able to use any of the many available test numbers (about 2000 in existence) but can only fall in that range.
Hence, var regex = /^256(7[7-8])[9-9]{4}|[0-9]{3}$/;