From 6192f3ed3f804638f0270625b42952717cfeb577 Mon Sep 17 00:00:00 2001 From: Leela Prasad Date: Thu, 11 Apr 2024 23:23:53 +0530 Subject: [PATCH 1/2] Fix withCore overriding request core options when using withAuth --- src/models/Spec.js | 5 +- test/component/interactions.spec.js | 73 +++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/models/Spec.js b/src/models/Spec.js index caa7ed5..c3e308e 100644 --- a/src/models/Spec.js +++ b/src/models/Spec.js @@ -1,6 +1,6 @@ const fs = require('fs'); const lc = require('lightcookie'); - +const override = require('deep-override'); const path = require('path'); const Tosser = require('./Tosser'); const Expect = require('./expect'); @@ -284,7 +284,8 @@ class Spec { } withCore(options) { - this._request.core = options; + this._request.core = this._request.core || {}; + override(this._request.core, options); return this; } diff --git a/test/component/interactions.spec.js b/test/component/interactions.spec.js index 09085a8..cbeaecb 100644 --- a/test/component/interactions.spec.js +++ b/test/component/interactions.spec.js @@ -604,6 +604,79 @@ describe('Mock', () => { .expectStatus(200); }); + it('GET - with core options & auth - override with auth', async () => { + await pactum.spec() + .useInteraction({ + request: { + method: 'GET', + path: '/api/core', + headers: { + 'authorization': 'Basic dXNlcjpwYXNz' + } + }, + response: { + status: 200 + } + }) + .get('http://localhost:9393') + .withCore({ + path: '/api/core', + auth: 'user:invalid-pass' + }) + .withAuth('user', 'pass') + .expectStatus(200); + }); + + it('GET - with core options & auth - override with core', async () => { + await pactum.spec() + .useInteraction({ + request: { + method: 'GET', + path: '/api/core', + headers: { + 'authorization': 'Basic dXNlcjpwYXNz' + } + }, + response: { + status: 200 + } + }) + .get('http://localhost:9393') + .withAuth('user', 'invalid-pass') + .withCore({ + path: '/api/core', + auth: 'user:pass' + }) + .expectStatus(200); + }); + + it.only('GET - with core options & auth - override with core invalid auth', async () => { + try { + await pactum.spec() + .useInteraction({ + request: { + method: 'GET', + path: '/api/core', + headers: { + 'authorization': 'Basic dXNlcjpwYXNz' + } + }, + response: { + status: 200 + } + }) + .get('http://localhost:9393') + .withAuth('user', 'pass') + .withCore({ + path: '/api/core', + auth: 'user:invalid-pass' + }) + } catch (error) { + err = error + } + expect(err.message).contains('Interaction not exercised: GET - /api/core'); + }); + it('GET - with auth', async () => { await pactum.spec() .useInteraction({ From 935ce721686ab4634c22d42039ff5ee6fae70aa6 Mon Sep 17 00:00:00 2001 From: Anudeep Date: Fri, 12 Apr 2024 11:36:24 +0530 Subject: [PATCH 2/2] remove only in test case --- test/component/interactions.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/component/interactions.spec.js b/test/component/interactions.spec.js index cbeaecb..601b6d4 100644 --- a/test/component/interactions.spec.js +++ b/test/component/interactions.spec.js @@ -650,7 +650,7 @@ describe('Mock', () => { .expectStatus(200); }); - it.only('GET - with core options & auth - override with core invalid auth', async () => { + it('GET - with core options & auth - override with core invalid auth', async () => { try { await pactum.spec() .useInteraction({