Test Overview
This test sends a GraphQL query in the request body using Postman. It verifies that the response contains the expected data field with correct values.
This test sends a GraphQL query in the request body using Postman. It verifies that the response contains the expected data field with correct values.
pm.test("GraphQL response contains user data", function () { const jsonData = pm.response.json(); pm.expect(jsonData.data).to.have.property('user'); pm.expect(jsonData.data.user).to.have.property('id').that.is.a('string'); pm.expect(jsonData.data.user).to.have.property('name').that.is.a('string'); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman is ready with GraphQL request body set | - | PASS |
| 2 | Send POST request with GraphQL query in body | Request sent to GraphQL endpoint with body containing query { user { id name } } | - | PASS |
| 3 | Receive response from server | Response received with JSON body containing data.user object | - | PASS |
| 4 | Parse response JSON | Response body parsed into jsonData object | - | PASS |
| 5 | Check if 'data' property exists | jsonData contains 'data' key | pm.expect(jsonData.data).to.have.property('user') | PASS |
| 6 | Check if 'user' object has 'id' property of type string | jsonData.data.user has 'id' key with string value | pm.expect(jsonData.data.user).to.have.property('id').that.is.a('string') | PASS |
| 7 | Check if 'user' object has 'name' property of type string | jsonData.data.user has 'name' key with string value | pm.expect(jsonData.data.user).to.have.property('name').that.is.a('string') | PASS |
| 8 | Test ends with all assertions passed | All expected fields verified in response | - | PASS |