Else function is getting ignored in the test

Hello everyone,
I am new to postman and trying to run a test by using if-else conditional flow. But in my test the else part is not being read.
If the if assertion is false then the test stops without moving to else.
Please help me with this.

Below is my code - Here I have a key “mode” in my request body and I need to assert the test based on the value for that:

if (pm.expect(JSON.parse(pm.request.body.raw).mode).not.eql("sms"))
{
    pm.test("Status code is 400", function () {
        pm.response.to.have.status(400);
    });
}
else
{
    pm.test("Status code is 200", function () {
        pm.response.to.have.status(200);
    });
}

Hi @lunar-module-engine7,

you need to parse the entire response first. Your test should look like this

const response = pm.response.json();

if (response.mode != “sms”){
pm.test(“Status code is 400”, function () {
pm.response.to.have.status(400);
});
} else {
pm.test(“Status code is 200”, function () {
pm.response.to.have.status(200);
});
}