|
1 | 1 | import { HookData, HookErrors } from '../types/CommandParams.js'; |
2 | 2 |
|
3 | 3 | export abstract class BaseTestHook { |
4 | | - protected readonly _name: string; |
5 | | - protected readonly _endpoint: string; |
6 | | - protected readonly _data?: HookData; |
7 | | - protected readonly _errors?: HookErrors; |
| 4 | + protected readonly hookName: string; |
| 5 | + protected readonly endpoint: string; |
| 6 | + protected readonly hookData?: HookData; |
| 7 | + protected readonly hookErrors?: HookErrors; |
8 | 8 |
|
9 | 9 | constructor(name: string, endpoint: string, data?: HookData, errors?: HookErrors) { |
10 | | - this._name = name; |
11 | | - this._endpoint = endpoint; |
12 | | - this._data = data; |
13 | | - this._errors = errors; |
| 10 | + this.hookName = name; |
| 11 | + this.endpoint = endpoint; |
| 12 | + this.hookData = data; |
| 13 | + this.hookErrors = errors; |
14 | 14 | } |
15 | 15 |
|
16 | | - protected abstract _safePost(body: unknown): Promise<void>; |
| 16 | + protected abstract safePost(body: unknown): Promise<void>; |
17 | 17 |
|
18 | 18 | getMetadata() { |
19 | | - return { name: this._name }; |
| 19 | + return { name: this.hookName }; |
20 | 20 | } |
21 | 21 |
|
22 | | - protected _beforeEvaluationImpl( |
| 22 | + protected beforeEvaluationImpl( |
23 | 23 | hookContext: Record<string, unknown>, |
24 | 24 | data: Record<string, unknown>, |
25 | 25 | ): Record<string, unknown> { |
26 | | - if (this._errors?.beforeEvaluation) { |
27 | | - throw new Error(this._errors.beforeEvaluation); |
| 26 | + if (this.hookErrors?.beforeEvaluation) { |
| 27 | + throw new Error(this.hookErrors.beforeEvaluation); |
28 | 28 | } |
29 | | - this._safePost({ |
| 29 | + this.safePost({ |
30 | 30 | evaluationSeriesContext: hookContext, |
31 | 31 | evaluationSeriesData: data, |
32 | 32 | stage: 'beforeEvaluation', |
33 | 33 | }); |
34 | | - return { ...data, ...(this._data?.beforeEvaluation ?? {}) }; |
| 34 | + return { ...data, ...(this.hookData?.beforeEvaluation ?? {}) }; |
35 | 35 | } |
36 | 36 |
|
37 | | - protected _afterEvaluationImpl( |
| 37 | + protected afterEvaluationImpl( |
38 | 38 | hookContext: Record<string, unknown>, |
39 | 39 | data: Record<string, unknown>, |
40 | 40 | detail: unknown, |
41 | 41 | ): Record<string, unknown> { |
42 | | - if (this._errors?.afterEvaluation) { |
43 | | - throw new Error(this._errors.afterEvaluation); |
| 42 | + if (this.hookErrors?.afterEvaluation) { |
| 43 | + throw new Error(this.hookErrors.afterEvaluation); |
44 | 44 | } |
45 | | - this._safePost({ |
| 45 | + this.safePost({ |
46 | 46 | evaluationSeriesContext: hookContext, |
47 | 47 | evaluationSeriesData: data, |
48 | 48 | stage: 'afterEvaluation', |
49 | 49 | evaluationDetail: detail, |
50 | 50 | }); |
51 | | - return { ...data, ...(this._data?.afterEvaluation ?? {}) }; |
| 51 | + return { ...data, ...(this.hookData?.afterEvaluation ?? {}) }; |
52 | 52 | } |
53 | 53 | } |
0 commit comments