Skip to content

Commit

Permalink
Fix withCore overriding request core options when using withAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
leelaprasadv committed Apr 11, 2024
1 parent 47dbb61 commit 6192f3e
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/models/Spec.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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;
}

Expand Down
73 changes: 73 additions & 0 deletions test/component/interactions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 6192f3e

Please sign in to comment.