Skip to content

Commit 24d4772

Browse files
committed
Simplify tests.
1 parent 12f2e95 commit 24d4772

File tree

2 files changed

+25
-175
lines changed

2 files changed

+25
-175
lines changed

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

Lines changed: 25 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { LDContext, LDEvaluationDetail, LDLogger } from '@launchdarkly/js-sdk-co
22

33
import { Hook, IdentifySeriesResult } from '../../src/api/integrations/Hooks';
44
import HookRunner from '../../src/HookRunner';
5-
import { TestHook } from './TestHook';
65

76
describe('given a hook runner and test hook', () => {
87
let logger: LDLogger;
@@ -364,68 +363,32 @@ describe('given a hook runner and test hook', () => {
364363
const afterIdentifyOrder: string[] = [];
365364
const afterTrackOrder: string[] = [];
366365

367-
const hookA = new TestHook();
368-
hookA.beforeEvalImpl = (_context, data) => {
369-
beforeEvalOrder.push('a');
370-
return data;
371-
};
372-
hookA.afterEvalImpl = (_context, data, _detail) => {
373-
afterEvalOrder.push('a');
374-
return data;
375-
};
376-
hookA.beforeIdentifyImpl = (_context, data) => {
377-
beforeIdentifyOrder.push('a');
378-
return data;
379-
};
380-
hookA.afterIdentifyImpl = (_context, data, _result) => {
381-
afterIdentifyOrder.push('a');
382-
return data;
383-
};
384-
hookA.afterTrackImpl = () => {
385-
afterTrackOrder.push('a');
386-
};
387-
388-
const hookB = new TestHook();
389-
hookB.beforeEvalImpl = (_context, data) => {
390-
beforeEvalOrder.push('b');
391-
return data;
392-
};
393-
hookB.afterEvalImpl = (_context, data, _detail) => {
394-
afterEvalOrder.push('b');
395-
return data;
396-
};
397-
hookB.beforeIdentifyImpl = (_context, data) => {
398-
beforeIdentifyOrder.push('b');
399-
return data;
400-
};
401-
hookB.afterIdentifyImpl = (_context, data, _result) => {
402-
afterIdentifyOrder.push('b');
403-
return data;
404-
};
405-
hookB.afterTrackImpl = () => {
406-
afterTrackOrder.push('b');
407-
};
366+
const createMockHook = (id: string): Hook => ({
367+
getMetadata: jest.fn().mockReturnValue({ name: `Hook ${id}` }),
368+
beforeEvaluation: jest.fn().mockImplementation((_context, data) => {
369+
beforeEvalOrder.push(id);
370+
return data;
371+
}),
372+
afterEvaluation: jest.fn().mockImplementation((_context, data, _detail) => {
373+
afterEvalOrder.push(id);
374+
return data;
375+
}),
376+
beforeIdentify: jest.fn().mockImplementation((_context, data) => {
377+
beforeIdentifyOrder.push(id);
378+
return data;
379+
}),
380+
afterIdentify: jest.fn().mockImplementation((_context, data, _result) => {
381+
afterIdentifyOrder.push(id);
382+
return data;
383+
}),
384+
afterTrack: jest.fn().mockImplementation(() => {
385+
afterTrackOrder.push(id);
386+
}),
387+
});
408388

409-
const hookC = new TestHook();
410-
hookC.beforeEvalImpl = (_context, data) => {
411-
beforeEvalOrder.push('c');
412-
return data;
413-
};
414-
hookC.afterEvalImpl = (_context, data, _detail) => {
415-
afterEvalOrder.push('c');
416-
return data;
417-
};
418-
hookC.beforeIdentifyImpl = (_context, data) => {
419-
beforeIdentifyOrder.push('c');
420-
return data;
421-
};
422-
hookC.afterIdentifyImpl = (_context, data, _result) => {
423-
afterIdentifyOrder.push('c');
424-
return data;
425-
};
426-
hookC.afterTrackImpl = () => {
427-
afterTrackOrder.push('c');
428-
};
389+
const hookA = createMockHook('a');
390+
const hookB = createMockHook('b');
391+
const hookC = createMockHook('c');
429392

430393
const runner = new HookRunner(logger, [hookA, hookB]);
431394
runner.addHook(hookC);

packages/shared/sdk-client/__tests__/hooks/TestHook.ts

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)