Skip to content

Commit

Permalink
Merge pull request #116 from pactumjs/v3
Browse files Browse the repository at this point in the history
V3
  • Loading branch information
ASaiAnudeep authored Jan 22, 2022
2 parents 4250302 + 698d48c commit 616baf5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
Expand Down
15 changes: 12 additions & 3 deletions src/models/Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion src/models/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions test/component/expects.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 616baf5

Please sign in to comment.