Skip to content

Commit

Permalink
Merge pull request #104 from pactumjs/v3
Browse files Browse the repository at this point in the history
url bug fix
  • Loading branch information
ASaiAnudeep authored Dec 25, 2021
2 parents 81494b2 + a209209 commit cf4f01d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

This readme offers an basic introduction to the library. Head over to the full documentation at https://pactumjs.github.io

- [API Testing](https://pactumjs.github.io/#/api-testing)
- [API Testing](https://pactumjs.github.io/#/request-making)
- [Integration Testing](https://pactumjs.github.io/#/integration-testing)
- [Component Testing](https://pactumjs.github.io/#/component-testing)
- [Contract Testing](https://pactumjs.github.io/#/contract-testing)
Expand Down
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.0",
"version": "3.1.1",
"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.4",
"pactum-matchers": "^1.0.5",
"parse-graphql": "^1.0.0",
"phin": "^3.6.0",
"polka": "^0.5.2"
Expand Down
3 changes: 3 additions & 0 deletions src/exports/request.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
export function setDefaultHeaders(key: string, value: string): void;
export function setDefaultHeaders(headers: object): void;

export function setBasicAuth(username: string, password: string): void;
export function setBearerToken(token: string): void;

/**
* sets a default timeout to all the requests in ms
* @default 3000 ms
Expand Down
8 changes: 8 additions & 0 deletions src/exports/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ const request = {
}
},

setBasicAuth(username, password) {
config.request.headers['Authorization'] = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
},

setBearerToken(token) {
config.request.headers['Authorization'] = 'Bearer ' + token;
},

setDefaultTimeout(timeout) {
if (typeof timeout !== 'number') {
throw new PactumRequestError(`Invalid timeout provided - ${timeout}`);
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/requestProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const requestProcessor = {
};

function setBaseUrl(request) {
if (config.request.baseUrl && !request.url.startsWith('http')) {
if (config.request.baseUrl && request.url && !request.url.startsWith('http')) {
request.url = config.request.baseUrl + request.url;
}
const _url = url.parse(request.url);
Expand Down

0 comments on commit cf4f01d

Please sign in to comment.