Rakesh133
Rakesh133

Reputation: 381

How to do 'OR' Operation in POSTMAN Tool

I have a test to check if I am getting the object of the response array is either 1 Month or 3 Months or 6 Months etc.

I have created tests like ones below but these are passing all the time, even for the wrong entries.

pm.test ("validate each object returns correct Frequency ", () => {
var fre = JSON.parse(responseBody);
for (i = 0; i < responseJson.length; i++){
    pm.expect(fre[i].FREQUENCY) === (('1 Month') || ('3 Months') || ('6 Months') || ('1 Year rolling') || ('Since Inception'));
} });

and something like this

pm.test ("validate each object returns correct Frequency ", function(){
pm.expect(responseJson.every((fre) => {
    (fre.FREQUENCY) === ("1 Month") || ("3 Months") || ("6 Months") || ("1 Year rolling") || ("Since Inception");
})).to.be.true;
});

and tried this way too

pm.test ("validate each object returns correct Frequency ", function(){
pm.expect(responseJson.every((fre) => {
    pm.expect(fre.FREQUENCY).to.be.oneOf === ("1 Month"),("3 Months"),("6 Months"),("1 Year rolling"),("Since Inception");
})).to.be.true;});

My Json response is something like this

[     
    {
        "CURRENCY": "XXX",
        "FREQUENCY": "3 Months",
        "EFFECTIVEDATE": "XXXX",
        "RETURNS": 123123,
        "BENCHMARK": -231323
    },
    {
        "CURRENCY": "XXX",
        "FREQUENCY": "1 Month",
        "EFFECTIVEDATE": "XXXX",
        "RETURNS": 123123,
        "BENCHMARK": -231323
    }
]

Can someone please help me on this?

Upvotes: 1

Views: 179

Answers (1)

Danny Dainton
Danny Dainton

Reputation: 25929

You could do this, it was close to what you had already:

pm.test('Frequency Check', () => {
    _.each(pm.response.json(), (arrItem) => {
        pm.expect(arrItem.FREQUENCY).to.be.oneOf(["1 Month" , "3 Months" , "6 Months" , "1 Year rolling", "Since Inception"])
    })
})

I changed the response data slightly, so you can see what it looks like when it fails:

Postman

Upvotes: 1

Related Questions