How to validate a Response with numbers in Postman - postman

I got the following response - Pre-Note added with PIN (1368)
The PIN number will not be the same always, so, how can I write a re-runnable test to validate it?

pm.expect(pm.response.text()).to.match(/<text>Pre-Note added with PIN ([\d]{4})<\/text>/);
you can use chai match method that uses regex , here this rehex will validate the pin is 4digit number

Related

How to validate input text for integers and decimals only?

I cannot find the right answer for my case, so I posted my question here.
I'm validating the form in ASP.NET MVC and looking for the way to validate a text field to allow only numeric and decimal numbers like
1 or 1.5 or 1.65
If I have 1,65 I do not want this to be validated.
I have put a metadata on my Model's field like this: [RegularExpression(#"^(((\d{1})*))$")]
And have
#Html.ValidationMessageFor(m => m.ResolvedAmount, "", new { #class = "error" })
to validate the field.
Also, in my function I have the following to check the validation:
var validator = $("#main").kendoValidator().data('kendoValidator');
if(validator.validate()){some logic}
I validate for the required field, but cannot get my int/decimal validation working.
What do I need to have in order to validate it?

express router not working with routes that include regex

I'm new to node and unable to create a simple route which will include regex as on of the parameter
// student.js - route file for route /student
app.get('/student/:/^[a-z0-9-]+$/', function(req,res){
res.send('student found');
});
when i hit localhost:3000/student/student-slug it says Cannot GET /student/student-slug
two more question
1) how to get param which is of regex, usually we can do this var _student = res.param.student_name but i'm unable to think for the regex
2) how to set optional param, let's say for pagination, route is like
/list/students/ will show list of last x student but /list/students/48 will offset that value to 48th row
this question may be duplicate but i'm unable to find answer
You need to encode the uri string before pass to request and decode it in your route handler.
Usage is very clear:
encodeURIComponent(str);
And for decoding use:
decodeURIComponent(str);
check the official documentation here
also do checkout this blog post on escape vs encode vs encodeURIComponent

Testing multiple JSON lines response

I am trying to make a test in Postman to verify some content in a JSON response. If I just try to verify a single line from the JSON response everything is fine. My problem starts when I need to test multiple lines of the JSON response. Is always failing. Any suggestion?
tests["Body matches string"] = responseBody.has("\"name\": null,
\"nameType\": \"NON_REFUNDABLE\"");
If I understand your question correctly I'd like to suggest that you approach this in a different way.
Instead of looking at the entire response body and seeing if the strings match you could alternatively test the individual Json properties that make up the response body. For example you could do the following:
var data = JSON.parse(responseBody);
tests["name is null"] = data.name === null;
tests["nameType is non-refundable"] = data.nameType === "NON_REFUNDABLE";
There are other alternatives as well but this is the first that comes to mind. For some more ideas about testing using postman check out their documentation and examples.

WCF RIA Services DataAnnotations not working as expected

I'm having a hard time understanding why my DataAnnotation attributes aren't be used by the client DataForm. Below is the metadata attribute on a phone number field.
[DataType(DataType.PhoneNumber, ErrorMessage = "Please provide a valid phone number.")]
public string client_phone_home { get; set; }
When running the application, I can enter any string less than 10 digits in length. It can be letters, numbers, etc. If I enter more than 10 characters, the datavalidation throws a message saying that the client_phone_home field must be a string less than 10 characters in length. It doesn't use my error message, and doesn't indicate anything about the field requiring a valid phone number.
Anyone know why this dataannotation is not working on the client side?
Check this http://www.silverlightshow.net/items/WCF-RIA-Services-Part-6-Validating-Data.aspx .It has complete explaination about Data Annotation Validation Attributes,Custom Validation Attributes,Server-Side Validation.
and look into this also http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2010/07/27/silverlight-and-wcf-ria-services-6-validation.aspx

Regular expression for validating url with parameters

I have been searching high and low for a solution to this, but to no avail. I am trying to prevent users from entering poorly formed URLs. Currently I have this regular expression in place:
^(http|https)\://.*$
This does a check to make sure the user is using http or https in the URL. However I need to go a step further and validate the structure of the URL.
For example this URL: http://mytest.com/?=test is clearly invalid as the parameter is not specified. All of the regular expressions that I've found on the web return valid when I use this URL.
I've been using this site to test the expressions that I've been finding.
Look I think the best solution for testing the URL as :
var url="http://mytest.com/?=test";
Make 2 steps :
1- test only URL as :
http://mytest.com/
use pattern :
var pattern1= "^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)([A-Za-z]){2,3}(\/)?";
2- split URL string by using pattern1 to get the URL query string and IF URL has Query string then make test on It again by using the following pattern :
var query=url.split(pattern1);
var q_str = query[1];
var pattern2 = "^(\?)?([0-9A-Za-z]+=[0-9A-Za-z]+(\&)?)+$";
Good Luck,
I believe the problem you are having comes from the fact that what is or is not a valid parameter from a query string is not universally defined. And specifically for your problem, the criteria for a valid query is still not well defined from your single example of what should fail.
To be precise, check this out RFC3986#3.4
Maybe you can make up a criteria for what should be an "acceptable" query string and from that you can get an answer. ;)