33 basicPlatform ,
44 hasher ,
55 logger ,
6+ MockStreamingProcessor ,
67 setupMockStreamingProcessor ,
78} from '@launchdarkly/private-js-mocks' ;
89
@@ -12,13 +13,13 @@ import { Flags } from './types';
1213
1314jest . mock ( '@launchdarkly/js-sdk-common' , ( ) => {
1415 const actual = jest . requireActual ( '@launchdarkly/js-sdk-common' ) ;
15- const { MockStreamingProcessor } = jest . requireActual ( '@launchdarkly/private-js-mocks' ) ;
16+ const actualMock = jest . requireActual ( '@launchdarkly/private-js-mocks' ) ;
1617 return {
1718 ...actual ,
1819 ...{
1920 internal : {
2021 ...actual . internal ,
21- StreamingProcessor : MockStreamingProcessor ,
22+ StreamingProcessor : actualMock . MockStreamingProcessor ,
2223 } ,
2324 } ,
2425 } ;
@@ -147,25 +148,53 @@ describe('sdk-client object', () => {
147148
148149 test ( 'identify success' , async ( ) => {
149150 defaultPutResponse [ 'dev-test-flag' ] . value = false ;
150- const carContext : LDContext = { kind : 'car' , key : 'mazda-cx7 ' } ;
151+ const carContext : LDContext = { kind : 'car' , key : 'test-car ' } ;
151152
152153 await ldc . identify ( carContext ) ;
153154 const c = ldc . getContext ( ) ;
154155 const all = ldc . allFlags ( ) ;
155156
156157 expect ( c ) . toEqual ( {
157158 kind : 'multi' ,
158- car : { key : 'mazda-cx7 ' } ,
159+ car : { key : 'test-car ' } ,
159160 ...autoEnv ,
160161 } ) ;
161162 expect ( all ) . toMatchObject ( {
162163 'dev-test-flag' : false ,
163164 } ) ;
165+ expect ( MockStreamingProcessor ) . toHaveBeenCalledWith (
166+ expect . anything ( ) ,
167+ expect . anything ( ) ,
168+ '/stream/path' ,
169+ expect . anything ( ) ,
170+ undefined ,
171+ expect . anything ( ) ,
172+ ) ;
173+ } ) ;
174+
175+ test ( 'identify success withReasons' , async ( ) => {
176+ const carContext : LDContext = { kind : 'car' , key : 'test-car' } ;
177+ ldc = new LDClientImpl ( testSdkKey , AutoEnvAttributes . Enabled , basicPlatform , {
178+ logger,
179+ sendEvents : false ,
180+ withReasons : true ,
181+ } ) ;
182+
183+ await ldc . identify ( carContext ) ;
184+
185+ expect ( MockStreamingProcessor ) . toHaveBeenCalledWith (
186+ expect . anything ( ) ,
187+ expect . anything ( ) ,
188+ '/stream/path?withReasons=true' ,
189+ expect . anything ( ) ,
190+ undefined ,
191+ expect . anything ( ) ,
192+ ) ;
164193 } ) ;
165194
166195 test ( 'identify success without auto env' , async ( ) => {
167196 defaultPutResponse [ 'dev-test-flag' ] . value = false ;
168- const carContext : LDContext = { kind : 'car' , key : 'mazda-cx7 ' } ;
197+ const carContext : LDContext = { kind : 'car' , key : 'test-car ' } ;
169198 ldc = new LDClientImpl ( testSdkKey , AutoEnvAttributes . Disabled , basicPlatform , {
170199 logger,
171200 sendEvents : false ,
@@ -209,7 +238,7 @@ describe('sdk-client object', () => {
209238
210239 test ( 'identify error stream error' , async ( ) => {
211240 setupMockStreamingProcessor ( true ) ;
212- const carContext : LDContext = { kind : 'car' , key : 'mazda-3 ' } ;
241+ const carContext : LDContext = { kind : 'car' , key : 'test-car ' } ;
213242
214243 await expect ( ldc . identify ( carContext ) ) . rejects . toMatchObject ( {
215244 code : 401 ,
@@ -225,10 +254,10 @@ describe('sdk-client object', () => {
225254
226255 await ldc . identify ( context ) ;
227256
228- const carContext1 : LDContext = { kind : 'car' , key : 'mazda-cx ' } ;
257+ const carContext1 : LDContext = { kind : 'car' , key : 'test-car ' } ;
229258 await ldc . identify ( carContext1 ) ;
230259
231- const carContext2 : LDContext = { kind : 'car' , key : 'subaru-forrester ' } ;
260+ const carContext2 : LDContext = { kind : 'car' , key : 'test-car-2 ' } ;
232261 await ldc . identify ( carContext2 ) ;
233262
234263 expect ( emitter . listenerCount ( 'change' ) ) . toEqual ( 1 ) ;
0 commit comments