vlucas / frisby

Frisby is a REST API testing framework built on Jest that makes testing API endpoints easy, fast, and fun.

Home Page:http://frisbyjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to extract some paramater from body

amrsa1 opened this issue · comments

i want to extract some of the body parameters and save it as var so i can use it in another test of with same test lets say i wanna post some items after its posted it will get new ID i wanna extract then ID so i can delete this item in the next test of within same test

`describe ('Backend Validation', function () {
frisby.globalSetup({
request: {
headers: {
'cookie': 'role',
'company-service': 'company'
}
}
});

fit('1- Verify user can create ite, with valid data',function () {
    return frisby
        .post('https://xxxxv.xxxxx.com/api/customers/features', {
            customerFeatureTypeId: 1,
            customerFeatureTypeValue: "123007",
            AccountId: "31111"
        })
        .expect('status',200)
        .inspectBody()
});`

inspct body output :
Body: {"id":963,"customerFeatureTypeId":1,"customerFeatureTypeValue":"123007","AccountId":"31111"}

i want to extract this value of id (963)

You can do this by nesting tests. It's in the README here: https://github.com/vlucas/frisby#nested-dependent-http-calls

@vlucas
i have tried the following method as u mentioned but im getting this error below could provide a sample how to solve it

    fit('1- Verify user can create IMEI with valid data',function () {
        return frisby
            .post('https://dev.example', {
                customerFeatureTypeId: 1,
                customerFeatureTypeValue: D.randomNumber,
                AccountId: "31111"
            })
            .expect('status',200)
            .expect('json', '*',
                {id: Joi.number(),
                    customerSecurityFeatureTypeId: 1,
                    customerSecurityFeatureTypeValue: D.randomNumber
                })
            .then(function (res) {
                let postId = res.json[0].id;
                return frisby
                    .patch('https://dev.example.com/api/customers/features',
                        {
                            customerSecurityFeaturesToUpdate: [],
                            customerSecurityFeaturesToDelete: [{id: postId}]
                        })
            })
            .expect('status',200)
            .inspectBody()
    });

TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object..module.exports.internals.Any'
--- property '_currentJoi' closes the circle
at JSON.stringify ()

  at jsonContainsAssertion (node_modules/frisby/src/frisby/expects.js:71:104)
  at node_modules/frisby/src/frisby/utils.js:67:7
  at arrayEach (node_modules/lodash/lodash.js:516:11)
  at Function.forEach (node_modules/lodash/lodash.js:9342:14)
  at Object.withPath (node_modules/frisby/src/frisby/utils.js:66:7)
  at FrisbySpec.json (node_modules/frisby/src/frisby/expects.js:70:11)
  at node_modules/frisby/src/frisby/spec.js:418:23
  at node_modules/frisby/src/frisby/spec.js:247:34

console.log node_modules/frisby/src/frisby/spec.js:355

FAILURE Status: 200
JSON: {
    "id": 1011,
    "customerFeatureTypeId": 1,
    "customerFeatureTypeValue": "48841",
    "m2mAccountId": "31111",
    "m2mAccountName": "GMNA",
    "customerFeatureStatusId": 2,
}

Test Suites: 1 failed, 1 total

You are using json along with Joi objects:

.expect('json', '*',
                {id: Joi.number(),

Joi can only be used with jsonTypes.

solved thank you