Skip to content

Commit c224cd6

Browse files
committed
PR Feedback.
1 parent 4a15070 commit c224cd6

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

packages/shared/sdk-client/__tests__/HookRunner.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('given a hook runner and test hook', () => {
135135
it('should execute identify hooks', () => {
136136
const context: LDContext = { kind: 'user', key: 'user-123' };
137137
const timeout = 10;
138-
const identifyResult: IdentifyResult = 'completed';
138+
const identifyResult: IdentifyResult = { status: 'completed' };
139139

140140
const identifyCallback = hookRunner.identify(context, timeout);
141141
identifyCallback(identifyResult);
@@ -170,7 +170,7 @@ describe('given a hook runner and test hook', () => {
170170
const errorHookRunner = new HookRunner(logger, [errorHook]);
171171

172172
const identifyCallback = errorHookRunner.identify({ kind: 'user', key: 'user-123' }, 1000);
173-
identifyCallback('error');
173+
identifyCallback({ status: 'error' });
174174

175175
expect(logger.error).toHaveBeenCalledWith(
176176
expect.stringContaining(
@@ -182,7 +182,7 @@ describe('given a hook runner and test hook', () => {
182182
it('should pass identify series data from before to after hooks', () => {
183183
const context: LDContext = { kind: 'user', key: 'user-123' };
184184
const timeout = 10;
185-
const identifyResult: IdentifyResult = 'completed';
185+
const identifyResult: IdentifyResult = { status: 'completed' };
186186

187187
testHook.beforeIdentify = jest
188188
.fn()

packages/shared/sdk-client/__tests__/LDClientImpl.hooks.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ it('should use hooks registered during configuration', async () => {
4949
expect(testHook.afterIdentify).toHaveBeenCalledWith(
5050
{ context: { key: 'user-key' }, timeout: undefined },
5151
{},
52-
'completed',
52+
{ status: 'completed' },
5353
);
5454
expect(testHook.beforeEvaluation).toHaveBeenCalledWith(
5555
{ context: { key: 'user-key' }, defaultValue: false, flagKey: 'flag-key' },
@@ -114,7 +114,7 @@ it('should execute hooks that are added using addHook', async () => {
114114
expect(addedHook.afterIdentify).toHaveBeenCalledWith(
115115
{ context: { key: 'user-key' }, timeout: undefined },
116116
{},
117-
'completed',
117+
{ status: 'completed' },
118118
);
119119
expect(addedHook.beforeEvaluation).toHaveBeenCalledWith(
120120
{ context: { key: 'user-key' }, defaultValue: false, flagKey: 'flag-key' },
@@ -158,6 +158,12 @@ it('should execute both initial hooks and hooks added using addHook', async () =
158158
{
159159
sendEvents: false,
160160
hooks: [initialHook],
161+
logger: {
162+
debug: jest.fn(),
163+
info: jest.fn(),
164+
warn: jest.fn(),
165+
error: jest.fn(),
166+
},
161167
},
162168
factory,
163169
);
@@ -187,7 +193,7 @@ it('should execute both initial hooks and hooks added using addHook', async () =
187193
expect(initialHook.afterIdentify).toHaveBeenCalledWith(
188194
{ context: { key: 'user-key' }, timeout: undefined },
189195
{},
190-
'completed',
196+
{ status: 'completed' },
191197
);
192198
expect(initialHook.beforeEvaluation).toHaveBeenCalledWith(
193199
{ context: { key: 'user-key' }, defaultValue: false, flagKey: 'flag-key' },
@@ -214,7 +220,7 @@ it('should execute both initial hooks and hooks added using addHook', async () =
214220
expect(addedHook.afterIdentify).toHaveBeenCalledWith(
215221
{ context: { key: 'user-key' }, timeout: undefined },
216222
{},
217-
'completed',
223+
{ status: 'completed' },
218224
);
219225
expect(addedHook.beforeEvaluation).toHaveBeenCalledWith(
220226
{ context: { key: 'user-key' }, defaultValue: false, flagKey: 'flag-key' },

packages/shared/sdk-client/src/LDClientImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ export default class LDClientImpl implements LDClient {
254254

255255
return identifyPromise.then(
256256
(res) => {
257-
afterIdentify('completed');
257+
afterIdentify({ status: 'completed' });
258258
return res;
259259
},
260260
(e) => {
261-
afterIdentify('error');
261+
afterIdentify({ status: 'error' });
262262
throw e;
263263
},
264264
);

packages/shared/sdk-client/src/api/integrations/Hooks.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,19 @@ export interface IdentifySeriesData {
5656
readonly [index: string]: unknown;
5757
}
5858

59+
/**
60+
* The status an identify operation completed with.
61+
*/
62+
export type IdentifyStatus = 'completed' | 'error';
63+
5964
/**
6065
* The result applies to a single identify operation. An operation may complete
6166
* with an error and then later complete successfully. Only the first completion
6267
* will be executed in the evaluation series.
6368
*/
64-
export type IdentifyResult = 'completed' | 'error';
69+
export interface IdentifyResult {
70+
status: IdentifyStatus;
71+
}
6572

6673
/**
6774
* Interface for extending SDK functionality via hooks.

0 commit comments

Comments
 (0)