diff --git a/contract-tests/TestHook.js b/contract-tests/TestHook.js index 9cb2274f3..0c3457eb3 100644 --- a/contract-tests/TestHook.js +++ b/contract-tests/TestHook.js @@ -1,10 +1,11 @@ import got from 'got'; export default class TestHook { - constructor(name, endpoint, data) { + constructor(name, endpoint, data, errors) { this._name = name; this._endpoint = endpoint; this._data = data; + this._errors = errors; } async _safePost(body) { @@ -23,6 +24,9 @@ export default class TestHook { } beforeEvaluation(hookContext, data) { + if(this._errors?.beforeEvaluation) { + throw new Error(this._errors.beforeEvaluation); + } this._safePost({ evaluationSeriesContext: hookContext, evaluationSeriesData: data, @@ -32,6 +36,9 @@ export default class TestHook { } afterEvaluation(hookContext, data, detail) { + if(this._errors?.afterEvaluation) { + throw new Error(this._errors.afterEvaluation); + } this._safePost({ evaluationSeriesContext: hookContext, evaluationSeriesData: data, @@ -39,6 +46,7 @@ export default class TestHook { evaluationDetail: detail, }); + return { ...data, ...(this._data?.['afterEvaluation'] || {}) }; } } diff --git a/contract-tests/sdkClientEntity.js b/contract-tests/sdkClientEntity.js index c3891fad5..0734ba582 100644 --- a/contract-tests/sdkClientEntity.js +++ b/contract-tests/sdkClientEntity.js @@ -64,7 +64,7 @@ export function makeSdkConfig(options, tag) { } if (options.hooks) { cf.hooks = options.hooks.hooks.map( - (hook) => new TestHook(hook.name, hook.callbackUri, hook.data), + (hook) => new TestHook(hook.name, hook.callbackUri, hook.data, hook.errors), ); } return cf;