How to verify full body response within a Pre requisite script and compare with response body?

Thank you for your help Michael, really appreciate the effort , i have not tested it yet … but am sure it should work … ill get back momentarily

Hi Allen,

how would you write that in the tests tab?
if i have something like this -->
[

{

    "sectionId": 1,

    "sectionTitle": "Setup for Program Adminstrators",

    "enabled": true,

    "sortOrder": 1,

    "contents": [

        {

            "contentId": 1,

            "sectionId": 1,

            "contentTitle": "User Roles",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 1

        },

        {

            "contentId": 2,

            "sectionId": 1,

            "contentTitle": "Create New User",

            "pdfLink": "PDF",

            "videoLink": "Video",

            "sortOrder": 2

        },

        {

            "contentId": 3,

            "sectionId": 1,

            "contentTitle": "Create Self-Registration Code",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 3

        },

        {

do i just copy the whole response and add it to the test tabs…?

I’d do it like this:

const jsonData = pm.response.json();
const lastResponse = pm.collectionVariables.get('lastResponse');
if(lastResponse) {
  lastResponse = JSON.parse(lastResponse);
  pm.test('response is the same as last time', function(){
    pm.expect(jsonData).to.eql(lastResponse);
  });
}

pm.collectionVariables.set('lastResponse', jsonData);

Hi I did try that

I am getting an error…

should i copy over the current full body in the test tab so it has something to test against ?

I forgot to add in the script we’d need to stringify the response object.

const jsonData = pm.response.json();
const lastResponse = pm.collectionVariables.get('lastResponse');
if(lastResponse) {
  lastResponse = JSON.parse(lastResponse);
  pm.test('response is the same as last time', function(){
    pm.expect(jsonData).to.eql(lastResponse);
  });
}

pm.collectionVariables.set('lastResponse', JSON.stringify(jsonData));

I tried that i am getting an error , but my question is what if i put the whole body response in the test tab… like so :
pm.test(“Your test name”, function () {

var jsonData = pm.response.json();

pm.expect(jsonData.value).to.eql([

{

    "sectionId": 1,

    "sectionTitle": "Setup for Program Adminstrators",

    "enabled": true,

    "sortOrder": 1,

    "contents": [

        {

            "contentId": 1,

            "sectionId": 1,

            "contentTitle": "User Roles",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 1

        },

        {

            "contentId": 2,

            "sectionId": 1,

            "contentTitle": "Create New User",

            "pdfLink": "PDF",

            "videoLink": "Video",

            "sortOrder": 2

        },

        {

            "contentId": 3,

            "sectionId": 1,

            "contentTitle": "Create Self-Registration Code",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 3

        },

        {

            "contentId": 4,

            "sectionId": 1,

            "contentTitle": "User Management",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 4

        },

        {

            "contentId": 5,

            "sectionId": 1,

            "contentTitle": "Email Settings",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 5

        },

        {

            "contentId": 6,

            "sectionId": 1,

            "contentTitle": "Download RFIs",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 6

        },

        {

            "contentId": 7,

            "sectionId": 1,

            "contentTitle": "Manage Departments & Setup Hierarchies",

            "pdfLink": "PDF",

            "videoLink": "Video",

            "sortOrder": 7

        },

        {

            "contentId": 8,

            "sectionId": 1,

            "contentTitle": "Tracer Category Setup",

            "pdfLink": "PDF",

            "videoLink": "Video",

            "sortOrder": 8

        },

        {

            "contentId": 9,

            "sectionId": 1,

            "contentTitle": "Guest Access Setup",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 9

        }

    ]

},

{

    "sectionId": 2,

    "sectionTitle": "Standards for Program Adminstrators",

    "enabled": true,

    "sortOrder": 2,

    "contents": [

        {

            "contentId": 10,

            "sectionId": 2,

            "contentTitle": "User Guilde",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 1

        },

        {

            "contentId": 11,

            "sectionId": 2,

            "contentTitle": "User Roles",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 2

        },

        {

            "contentId": 12,

            "sectionId": 2,

            "contentTitle": "Filters & Service Profiles",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 3

        },

        {

            "contentId": 13,

            "sectionId": 2,

            "contentTitle": "Home Page Overview",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 4

        },

        {

            "contentId": 14,

            "sectionId": 2,

            "contentTitle": "Navigate and Score the EPs",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 5

        },

        {

            "contentId": 15,

            "sectionId": 2,

            "contentTitle": "Organization Documentation",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 6

        },

        {

            "contentId": 16,

            "sectionId": 2,

            "contentTitle": "Plan of Action Tips",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 7

        },

        {

            "contentId": 17,

            "sectionId": 2,

            "contentTitle": "Create Scoring Assignments",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 8

        },

        {

            "contentId": 18,

            "sectionId": 2,

            "contentTitle": "Re-assign EPs",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 9

        },

        {

            "contentId": 19,

            "sectionId": 2,

            "contentTitle": "Bulk Scoring & Bulk Plan of Action",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 10

        },

        {

            "contentId": 20,

            "sectionId": 2,

            "contentTitle": "Cross Program Scoring",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 11

        },

        {

            "contentId": 21,

            "sectionId": 2,

            "contentTitle": "Create & Manage Tasks",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 12

        },

        {

            "contentId": 22,

            "sectionId": 2,

            "contentTitle": "Data Migration Reset",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 13

        },

        {

            "contentId": 23,

            "sectionId": 2,

            "contentTitle": "Upload and Submit FSA",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 14

        },

        {

            "contentId": 24,

            "sectionId": 2,

            "contentTitle": "FSA Submission Options",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 15

        },

        {

            "contentId": 25,

            "sectionId": 2,

            "contentTitle": "Email Communication",

            "pdfLink": "PDF",

            "videoLink": null,

            "sortOrder": 16

        },

        {

            "contentId": 26,

            "sectionId": 2,

            "contentTitle": "Presonal Profile Management",

            "pdfLink": "PDF",

            "videoLink": "Video",

            "sortOrder": 17

        },

        {

            "contentId": 27,

            "sectionId": 2,

            "contentTitle": "Reset Password Instructions",

            "pdfLink": "PDF",

            "videoLink": "Video",

            "sortOrder": 18

        }

    ]

}

]);

});

and then lets if i run it next week, it should have the same result, if its different than theres an issue …
i did notice this is what i am getting if i click send:

You can do it that way, but it’s effectively the same as setting it to a variable. Plus doing it this way means you have to continuously maintain the test.

You’re getting an error in your test because jsonData.value doesn’t exist in your response. try removing .value

How do you know these things ? Awesome worked …:slight_smile:

so this solution is basically grabbing all the data and comparing real time test tab to the current body,
(Also if lets say sectionid:1 is actually sectionid:2, then how would i debug that
in the console?

looking at your code of “last response” how does PM know what last response is?

You showed me the response, I saw there was no value property :slight_smile:

I haven’t tried this, but you might be able to use the code from here to do a diff and print to the console.

Hi I have another question please if you could help