|
1 | 1 | import type { EvaluationDetails, BaseHook, HookContext } from '@openfeature/core'; |
2 | 2 | import { DebounceHook } from './debounce-hook'; |
3 | 3 | import type { Hook as WebSdkHook } from '@openfeature/web-sdk'; |
| 4 | +import { OpenFeature as OpenFeatureWeb } from '@openfeature/web-sdk'; |
4 | 5 | import type { Hook as ServerSdkHook } from '@openfeature/server-sdk'; |
| 6 | +import { OpenFeature as OpenFeaturServer } from '@openfeature/server-sdk'; |
5 | 7 |
|
6 | 8 | describe('DebounceHook', () => { |
7 | 9 | describe('caching', () => { |
@@ -203,6 +205,23 @@ describe('DebounceHook', () => { |
203 | 205 |
|
204 | 206 | describe('SDK compatibility', () => { |
205 | 207 | describe('web-sdk hooks', () => { |
| 208 | + it('should have type compatibility with API, client, evaluation', () => { |
| 209 | + const webSdkHook = {} as WebSdkHook; |
| 210 | + |
| 211 | + const hook = new DebounceHook<number>(webSdkHook, { |
| 212 | + debounceTime: 60_000, |
| 213 | + maxCacheItems: 100, |
| 214 | + }); |
| 215 | + |
| 216 | + OpenFeatureWeb.addHooks(hook); |
| 217 | + const client = OpenFeatureWeb.getClient().addHooks(hook); |
| 218 | + client.getBooleanValue('flag', false, { hooks: [hook] }); |
| 219 | + |
| 220 | + // these expectations are silly, the real test here is making sure the above compiles |
| 221 | + expect(OpenFeatureWeb.getHooks().length).toEqual(1); |
| 222 | + expect(client.getHooks().length).toEqual(1); |
| 223 | + }); |
| 224 | + |
206 | 225 | it('should debounce synchronous hooks', () => { |
207 | 226 | const innerWebSdkHook: WebSdkHook = { |
208 | 227 | before: jest.fn(), |
@@ -239,6 +258,23 @@ describe('DebounceHook', () => { |
239 | 258 | const contextKey = 'key'; |
240 | 259 | const contextValue = 'value'; |
241 | 260 | const evaluationContext = { [contextKey]: contextValue }; |
| 261 | + it('should have type compatibility with API, client, evaluation', () => { |
| 262 | + const serverHook = {} as ServerSdkHook; |
| 263 | + |
| 264 | + const hook = new DebounceHook<number>(serverHook, { |
| 265 | + debounceTime: 60_000, |
| 266 | + maxCacheItems: 100, |
| 267 | + }); |
| 268 | + |
| 269 | + OpenFeaturServer.addHooks(hook); |
| 270 | + const client = OpenFeaturServer.getClient().addHooks(hook); |
| 271 | + client.getBooleanValue('flag', false, {}, { hooks: [hook] }); |
| 272 | + |
| 273 | + // these expectations are silly, the real test here is making sure the above compiles |
| 274 | + expect(OpenFeaturServer.getHooks().length).toEqual(1); |
| 275 | + expect(client.getHooks().length).toEqual(1); |
| 276 | + }); |
| 277 | + |
242 | 278 | it('should debounce synchronous hooks', () => { |
243 | 279 | const innerServerSdkHook: ServerSdkHook = { |
244 | 280 | before: jest.fn(() => { |
|
0 commit comments