Confirm results in response contain a filetype

Hi Guys, Iā€™m brand new to Postman and brand new to coding so i am trying to teach myself on the fly as I start in my new job.

If I have a response to an APi request which looks like this :

{
    "results": [
        "/var/local/****/****/Pbx123.clf"
    ]
}

What is the syntax for a test to confirm that there is a .clf file contained in the response.

I have tried this and a few different variations of it

pm.response.to.have.status(200);
    pm.response.to.be.withBody;
    pm.response.to.be.json;
    pm.response.contains(".clf"); 

The clf part is the part I am having problems with.

Hey @markst33

Welcome to the community! :trophy:

You can use regex with the .to.match() chaiJS assertion to check that file extension:

pm.test("File Path Check", () => {
    pm.expect(pm.response.json().results[0]).to.match(/^.*\.clf$/);
}); 

You can also check for different extensions using the same method like they have done here:

1 Like