Skip to content

Commit

Permalink
chore: Add support for hook errors contract test. (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion authored Apr 3, 2024
1 parent e27f298 commit d120bec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion contract-tests/TestHook.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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,
Expand All @@ -32,13 +36,17 @@ export default class TestHook {
}

afterEvaluation(hookContext, data, detail) {
if(this._errors?.afterEvaluation) {
throw new Error(this._errors.afterEvaluation);
}
this._safePost({
evaluationSeriesContext: hookContext,
evaluationSeriesData: data,
stage: 'afterEvaluation',
evaluationDetail: detail,
});


return { ...data, ...(this._data?.['afterEvaluation'] || {}) };
}
}
2 changes: 1 addition & 1 deletion contract-tests/sdkClientEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d120bec

Please sign in to comment.