Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix withCore overriding request core options when using withAuth #345

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 () => {
ASaiAnudeep marked this conversation as resolved.
Show resolved Hide resolved
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
Loading