diff --git a/package-lock.json b/package-lock.json index d3bd21c..1173c91 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "pactum", - "version": "3.1.2", + "version": "3.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1655,9 +1655,9 @@ } }, "pactum-matchers": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/pactum-matchers/-/pactum-matchers-1.0.6.tgz", - "integrity": "sha512-vUXnIAEmQdg3tKXzcj2OFhB1A492u+c89ps6JY6aDH0xH29fbyDYmnHl4xtp3peQosq8AOqC9D6eTXMAhcE5xw==" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/pactum-matchers/-/pactum-matchers-1.1.0.tgz", + "integrity": "sha512-3yeLEqLk8Kk5NqFLCuuGZcbeJUZNVjSOm46+/Y27Wo/Xe4ymySJ2D7R/aE/q+8uBwtanqw1x5RRP+XR8Mcm1Gw==" }, "parse-graphql": { "version": "1.0.0", diff --git a/package.json b/package.json index 9b7a34b..00bc0e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pactum", - "version": "3.1.2", + "version": "3.1.3", "description": "REST API Testing Tool for all levels in a Test Pyramid", "main": "./src/index.js", "types": "./src/index.d.ts", @@ -67,7 +67,7 @@ "klona": "^2.0.4", "lightcookie": "^1.0.25", "openapi-fuzzer-core": "^1.0.6", - "pactum-matchers": "^1.0.6", + "pactum-matchers": "^1.1.0", "parse-graphql": "^1.0.0", "phin": "^3.6.0", "polka": "^0.5.2" diff --git a/src/models/Spec.js b/src/models/Spec.js index 1e154e1..b834c7c 100644 --- a/src/models/Spec.js +++ b/src/models/Spec.js @@ -211,12 +211,21 @@ class Spec { if (!this._request.headers) { this._request.headers = {}; } - const cookieObject = utils.createCookieObject(key, value); + let cookie; + if (typeof key === 'object') { + cookie = lc.serialize(key); + } else { + if (value) { + cookie = `${key}=${value}`; + } else { + cookie = key; + } + } const headers = this._request.headers; if (headers['cookie'] !== undefined) { - headers['cookie'] = headers['cookie'] + ';' + lc.serialize(cookieObject); + headers['cookie'] = headers['cookie'] + ';' + cookie; } else { - headers['cookie'] = lc.serialize(cookieObject); + headers['cookie'] = cookie; } return this; } diff --git a/src/models/expect.js b/src/models/expect.js index a5af6f7..9ee757d 100644 --- a/src/models/expect.js +++ b/src/models/expect.js @@ -342,7 +342,12 @@ class Expect { for (let i = 0; i < this.jsonSnapshot.length; i++) { const data = this.jsonSnapshot[i]; if (data) { - Object.assign(rules, jmv.getMatchingRules(data, '$.body')); + const current_rules = jmv.getMatchingRules(data, '$.body'); + const errors = jmv.validate(actual, jmv.getRawValue(data), current_rules, '$.body'); + if (errors) { + this.fail(errors.replace('$.body', '$')); + } + Object.assign(rules, current_rules); } } if (Object.keys(rules).length > 0) { diff --git a/test/component/expects.spec.js b/test/component/expects.spec.js index 2a66680..f37be29 100644 --- a/test/component/expects.spec.js +++ b/test/component/expects.spec.js @@ -1007,6 +1007,28 @@ describe('Expects', () => { expect(err2).not.undefined; }); + it('json snapshot - with invalid matchers', async () => { + let e; + try { + await pactum.spec() + .useInteraction('get people') + .name('json snapshot - with invalid matchers') + .get('http://localhost:9393/api/people') + .expectStatus(200) + .useLogLevel('ERROR') + .expectJsonSnapshot({ + id: like('id') + }) + .expectJsonSnapshot({ + createdAt: like('2020-02-02') + }); + } catch (error) { + e = error; + } + expect(e).not.undefined; + fs.unlinkSync(`.pactum/snapshots/json snapshot - with invalid matchers.json`); + }); + it('error - empty', async () => { await pactum.spec() .get('http://localhost:9392')