We help IT Professionals succeed at work.

Postman Test (Javascript) issue with looping an array

Eddie Shipman
on
60 Views
Last Modified: 2019-05-06
Let's say that I have the following Postman test:
    
    var U = data.vCustomer.userDefFlds;
    tests["UDF1  : Matched"] = U[0].udfValue === "CUST_UDF1";
    tests["UDF2  : Matched"] = U[11].udfValue === "CUST_UDF2";
    tests["UDF3  : Matched"] = U[22].udfValue === "CUST_UDF3";
    tests["UDF4  : Matched"] = U[33].udfValue === "CUST_UDF4";
    tests["UDF5  : Matched"] = U[44].udfValue === "CUST_UDF5";
    tests["UDF6  : Matched"] = U[46].udfValue === "CUST_UDF6";
    tests["UDF7  : Matched"] = U[47].udfValue === "CUST_UDF7";
    tests["UDF8  : Matched"] = U[48].udfValue === "CUST_UDF8";
    tests["UDF9  : Matched"] = U[49].udfValue === "CUST_UDF9";
    tests["UDF10 : Matched"] = U[1].udfValue === "CUST_UDF10";
    tests["UDF11 : Matched"] = U[2].udfValue === "CUST_UDF11";
    tests["UDF12 : Matched"] = U[3].udfValue === "CUST_UDF12";
    tests["UDF13 : Matched"] = U[4].udfValue === "CUST_UDF13";
    tests["UDF14 : Matched"] = U[5].udfValue === "CUST_UDF14";
    tests["UDF15 : Matched"] = U[6].udfValue === "CUST_UDF15";
    tests["UDF16 : Matched"] = U[7].udfValue === "CUST_UDF16";
    tests["UDF17 : Matched"] = U[8].udfValue === "CUST_UDF17";
    tests["UDF18 : Matched"] = U[9].udfValue === "CUST_UDF18";
    tests["UDF19 : Matched"] = U[10].udfValue === "CUST_UDF19";
    tests["UDF20 : Matched"] = U[12].udfValue === "CUST_UDF20";
    tests["UDF21 : Matched"] = U[13].udfValue === "CUST_UDF21";
    tests["UDF22 : Matched"] = U[14].udfValue === "CUST_UDF22";
    tests["UDF23 : Matched"] = U[15].udfValue === "CUST_UDF23";
    tests["UDF24 : Matched"] = U[16].udfValue === "CUST_UDF24";
    tests["UDF25 : Matched"] = U[17].udfValue === "CUST_UDF25";
    tests["UDF26 : Matched"] = U[18].udfValue === "CUST_UDF26";
    tests["UDF27 : Matched"] = U[19].udfValue === "CUST_UDF27";
    tests["UDF28 : Matched"] = U[20].udfValue === "CUST_UDF28";
    tests["UDF29 : Matched"] = U[21].udfValue === "CUST_UDF29";
    tests["UDF30 : Matched"] = U[23].udfValue === "CUST_UDF30";
    tests["UDF31 : Matched"] = U[24].udfValue === "CUST_UDF31";
    tests["UDF32 : Matched"] = U[25].udfValue === "CUST_UDF32";
    tests["UDF33 : Matched"] = U[26].udfValue === "CUST_UDF33";
    tests["UDF34 : Matched"] = U[27].udfValue === "CUST_UDF34";
    tests["UDF35 : Matched"] = U[28].udfValue === "CUST_UDF35";
    tests["UDF36 : Matched"] = U[29].udfValue === "CUST_UDF36";
    tests["UDF37 : Matched"] = U[30].udfValue === "CUST_UDF37";
    tests["UDF38 : Matched"] = U[31].udfValue === "CUST_UDF38";
    tests["UDF39 : Matched"] = U[32].udfValue === "CUST_UDF39";
    tests["UDF40 : Matched"] = U[34].udfValue === "CUST_UDF40";
    tests["UDF41 : Matched"] = U[35].udfValue === "CUST_UDF41";
    tests["UDF42 : Matched"] = U[36].udfValue === "CUST_UDF42";
    tests["UDF43 : Matched"] = U[37].udfValue === "CUST_UDF43";
    tests["UDF44 : Matched"] = U[38].udfValue === "CUST_UDF44";
    tests["UDF45 : Matched"] = U[39].udfValue === "CUST_UDF45";
    tests["UDF46 : Matched"] = U[40].udfValue === "CUST_UDF46";
    tests["UDF47 : Matched"] = U[41].udfValue === "CUST_UDF47";
    tests["UDF48 : Matched"] = U[42].udfValue === "CUST_UDF48";
    tests["UDF49 : Matched"] = U[43].udfValue === "CUST_UDF49";
    tests["UDF50 : Matched"] = U[45].udfValue === "CUST_UDF50";

Open in new window

The tests are written in javascript.
I want to replicate this using only a for loop but I don't think a simple loop will work because CUST_UDF10 = U[1] & CUST_UDF2 = U[11];
If I sort the array U, that gives me issues with CUST_UDF1, CUST_UDF10, and CUST_UDF32.

What am I doing wrong here?

    U.sort();
    for(i=0;i<50;i++) {
        x = i+1;
        tests["UDF"+x+"  : Matched"] = U[i].udfValue === "CUST_UDF"+x;
    }

Open in new window

Comment
Watch Question

vogenAnalyst Programmer
CERTIFIED EXPERT

Commented:
Your index of tests starting from 1
vogenAnalyst Programmer
CERTIFIED EXPERT

Commented:
I see issue with tests. Number of spaces in between UDF[x] and colon(:) from 1-9
Eddie ShipmanAll-around developer
CERTIFIED EXPERT

Author

Commented:
Your index of tests starting from 1
No, the Index is 0, the Name of the tests begin with 1.

I see issue with tests. Number of spaces in between UDF[x] and colon(:) from 1-9

That is just the names of the tests, no issues
Sr. Developer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.