diff --git a/README.md b/README.md index 9df4033..7600992 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/package-lock.json b/package-lock.json index b2b100a..7d36d77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "pactum", - "version": "3.1.0", + "version": "3.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1655,9 +1655,9 @@ } }, "pactum-matchers": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/pactum-matchers/-/pactum-matchers-1.0.4.tgz", - "integrity": "sha512-mNOND/ICMu0kupYExpymnQxT8OgRBkGiidQWdtjP9Vdd4RJWuE/GxcMCyaClg+5CpIewn5VlJEvq5K4IKxU36A==" + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/pactum-matchers/-/pactum-matchers-1.0.5.tgz", + "integrity": "sha512-WANTu9+JDIo079pCAXQGsLWepdUtj0bXU+uzPSbeE/H9a6TYfi4793Gkt4QY3+t46c5n5KdDnCCYtGugrYZlcg==" }, "parse-graphql": { "version": "1.0.0", diff --git a/package.json b/package.json index f490035..9224d4f 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" diff --git a/src/exports/request.d.ts b/src/exports/request.d.ts index 7539750..fb302c3 100644 --- a/src/exports/request.d.ts +++ b/src/exports/request.d.ts @@ -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 diff --git a/src/exports/request.js b/src/exports/request.js index 0dfe8d1..bcf43ce 100644 --- a/src/exports/request.js +++ b/src/exports/request.js @@ -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}`); diff --git a/src/helpers/requestProcessor.js b/src/helpers/requestProcessor.js index e76f391..e2659ef 100644 --- a/src/helpers/requestProcessor.js +++ b/src/helpers/requestProcessor.js @@ -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);