Comparing version 3.0.4 to 3.0.5
{ | ||
"name": "pactum", | ||
"version": "3.0.4", | ||
"version": "3.0.5", | ||
"description": "REST API Testing Tool for all levels in a Test Pyramid", | ||
@@ -13,6 +13,3 @@ "main": "./src/index.js", | ||
"./handler": "./src/exports/handler.js", | ||
"./matcher": "./src/exports/matcher.js", | ||
"./mock": "./src/exports/mock.js", | ||
"./pact": "./src/exports/pact.js", | ||
"./provider": "./src/exports/provider.js", | ||
"./request": "./src/exports/request.js", | ||
@@ -19,0 +16,0 @@ "./settings": "./src/exports/settings.js", |
@@ -16,3 +16,3 @@ export interface Have { | ||
responseTimeLessThan(ms: number): void; | ||
_(handler: string, data: any): void | ||
_(handler: string, data: any): Promise<void>; | ||
} | ||
@@ -19,0 +19,0 @@ |
@@ -83,7 +83,7 @@ const ExpectModel = require('../models/expect'); | ||
this.expect.customExpectHandlers.push({ handler, data }); | ||
this._validate(); | ||
return this._validate(); | ||
} | ||
_validate() { | ||
this.expect.validate({}, this.response); | ||
return this.expect.validate({}, this.response); | ||
} | ||
@@ -90,0 +90,0 @@ |
@@ -31,2 +31,6 @@ import * as Spec from '../models/Spec'; | ||
interface CaptureContext extends RequestResponseContext { | ||
store?: object; | ||
} | ||
interface ExpectHandlerContext extends RequestResponseContext { | ||
@@ -57,3 +61,3 @@ data?: any; | ||
export type RetryHandlerFunction = (ctx: RequestResponseContext) => boolean; | ||
export type ReturnHandlerFunction = (ctx: RequestResponseContext) => any; | ||
export type CaptureHandlerFunction = (ctx: CaptureContext) => any; | ||
export type StateHandlerFunction = (ctx: StateHandlerContext) => any; | ||
@@ -82,3 +86,3 @@ export type DataHandlerFunction = (ctx: DataHandlerContext) => any; | ||
*/ | ||
export function addCaptureHandler(name: string, func: ReturnHandlerFunction): void; | ||
export function addCaptureHandler(name: string, func: CaptureHandlerFunction): void; | ||
@@ -93,3 +97,3 @@ /** | ||
*/ | ||
export function addDataFunHandler(name: string, func: DataHandlerFunction): void; | ||
export function addDataFuncHandler(name: string, func: DataHandlerFunction): void; | ||
@@ -96,0 +100,0 @@ /** |
@@ -65,3 +65,3 @@ const { PactumHandlerError } = require('../helpers/errors'); | ||
addDataFunHandler(name, func) { | ||
addDataFuncHandler(name, func) { | ||
isValidHandler(name, func); | ||
@@ -72,3 +72,3 @@ dataHandlers[name] = func; | ||
getDataFunHandler(name) { | ||
getDataFuncHandler(name) { | ||
if (dataHandlers[name]) return dataHandlers[name]; | ||
@@ -75,0 +75,0 @@ throw new PactumHandlerError(`Data Handler Not Found - '${name}'`); |
@@ -33,2 +33,6 @@ /** | ||
export function addDataTemplate(templates: object): void; | ||
export function addDataTemplate(templates: object[]): void; | ||
export function addDataTemplate(templates: object[]): void; | ||
export function getDataMap(): object; | ||
export function getDataTemplate(): object; | ||
export function getDataStore(): object; |
@@ -102,3 +102,3 @@ const override = require('deep-override'); | ||
const [handlerName, ..._args] = refValue.split(':'); | ||
const handlerFun = handler.getDataFunHandler(handlerName); | ||
const handlerFun = handler.getDataFuncHandler(handlerName); | ||
values.push(handlerFun({ args: _args.length > 0 ? _args[0].split(',') : _args })); | ||
@@ -105,0 +105,0 @@ } |
@@ -34,3 +34,3 @@ const jqy = require('json-query'); | ||
function storeSpecData(spec, stores) { | ||
const ctx = { req: spec._request, res: spec._response }; | ||
const ctx = { req: spec._request, res: spec._response, store: stash.getDataStore() }; | ||
for (let i = 0; i < stores.length; i++) { | ||
@@ -37,0 +37,0 @@ const store = stores[i]; |
@@ -51,3 +51,4 @@ const assert = require('assert'); | ||
this._validateResponseTime(response); | ||
this._validateCustomExpectHandlers(request, response); | ||
// for asynchronous expectations | ||
return this._validateCustomExpectHandlers(request, response); | ||
} | ||
@@ -317,3 +318,3 @@ | ||
_validateCustomExpectHandlers(request, response) { | ||
async _validateCustomExpectHandlers(request, response) { | ||
for (let i = 0; i < this.customExpectHandlers.length; i++) { | ||
@@ -323,6 +324,6 @@ const requiredHandler = this.customExpectHandlers[i]; | ||
if (typeof requiredHandler.handler === 'function') { | ||
requiredHandler.handler(ctx); | ||
await requiredHandler.handler(ctx); | ||
} else { | ||
const handlerFun = handler.getExpectHandler(requiredHandler.handler); | ||
handlerFun(ctx); | ||
await handlerFun(ctx); | ||
} | ||
@@ -329,0 +330,0 @@ } |
@@ -37,3 +37,3 @@ const phin = require('phin'); | ||
th.storeSpecData(this.spec, this.spec._stores); | ||
this.validate(); | ||
await this.validate(); | ||
return th.getOutput(this.spec, this.spec._returns); | ||
@@ -115,7 +115,7 @@ } | ||
validate() { | ||
async validate() { | ||
this.validateError(); | ||
try { | ||
this.validateInteractions(); | ||
this.validateResponse(); | ||
await this.validateResponse(); | ||
this.spec.status = 'PASSED'; | ||
@@ -145,4 +145,4 @@ rlc.afterSpecReport(this.spec); | ||
validateResponse() { | ||
this.expect.validate(this.request, this.response); | ||
async validateResponse() { | ||
await this.expect.validate(this.request, this.response); | ||
} | ||
@@ -149,0 +149,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132593
4087