Skip to content

Commit 960eaec

Browse files
[FSSDK-10936] test adjustment
1 parent 03e4bb4 commit 960eaec

File tree

5 files changed

+7
-54
lines changed

5 files changed

+7
-54
lines changed

lib/event_processor/event_processor_factory.react_native.spec.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -154,28 +154,10 @@ describe('createBatchEventProcessor', () => {
154154

155155
it('should throw error if @react-native-async-storage/async-storage is not available', async () => {
156156
isAsyncStorageAvailable = false;
157-
const { getBatchEventProcessor } = await vi.importActual<typeof import('./event_processor_factory')>(
158-
'./event_processor_factory'
159-
);
160157
const { AsyncStorageCache } = await vi.importActual<
161158
typeof import('../utils/cache/async_storage_cache.react_native')
162159
>('../utils/cache/async_storage_cache.react_native');
163160

164-
mockGetBatchEventProcessor.mockImplementationOnce(() => {
165-
return getBatchEventProcessor(
166-
{
167-
eventDispatcher: defaultEventDispatcher,
168-
flushInterval: 1000,
169-
batchSize: 10,
170-
retryOptions: {
171-
maxRetries: 5,
172-
},
173-
failedEventRetryInterval: FAILED_EVENT_RETRY_INTERVAL,
174-
},
175-
BatchEventProcessor
176-
);
177-
});
178-
179161
MockAsyncStorageCache.mockImplementationOnce(() => {
180162
return new AsyncStorageCache();
181163
});
@@ -192,29 +174,11 @@ describe('createBatchEventProcessor', () => {
192174
const eventStore = {
193175
operation: 'sync',
194176
} as SyncCache<string>;
195-
const { getBatchEventProcessor } = await vi.importActual<typeof import('./event_processor_factory')>(
196-
'./event_processor_factory'
197-
);
177+
198178
const { AsyncStorageCache } = await vi.importActual<
199179
typeof import('../utils/cache/async_storage_cache.react_native')
200180
>('../utils/cache/async_storage_cache.react_native');
201181

202-
mockGetBatchEventProcessor.mockImplementationOnce(() => {
203-
return getBatchEventProcessor(
204-
{
205-
eventDispatcher: defaultEventDispatcher,
206-
flushInterval: 1000,
207-
batchSize: 10,
208-
eventStore: getPrefixEventStore(eventStore),
209-
retryOptions: {
210-
maxRetries: 5,
211-
},
212-
failedEventRetryInterval: FAILED_EVENT_RETRY_INTERVAL,
213-
},
214-
BatchEventProcessor
215-
);
216-
});
217-
218182
MockAsyncStorageCache.mockImplementationOnce(() => {
219183
return new AsyncStorageCache();
220184
});

lib/plugins/key_value_cache/reactNativeAsyncStorageCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { getDefaultAsyncStorage } from '../../utils/import.react_native/@react-n
1919

2020
export default class ReactNativeAsyncStorageCache implements PersistentKeyValueCache {
2121
private asyncStorage = getDefaultAsyncStorage();
22-
22+
2323
async contains(key: string): Promise<boolean> {
2424
return (await this.asyncStorage.getItem(key)) !== null;
2525
}

lib/project_config/config_manager_factory.react_native.spec.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ describe('createPollingConfigManager', () => {
133133

134134
it('Should not throw error if a cache is present in the config, and async storage is not available', async () => {
135135
isAsyncStorageAvailable = false;
136-
const { getPollingConfigManager } = await vi.importActual<typeof import('./config_manager_factory')>(
137-
'./config_manager_factory'
138-
);
139136
const { default: ReactNativeAsyncStorageCache } = await vi.importActual<
140137
typeof import('../plugins/key_value_cache/reactNativeAsyncStorageCache')
141138
>('../plugins/key_value_cache/reactNativeAsyncStorageCache');
@@ -145,10 +142,6 @@ describe('createPollingConfigManager', () => {
145142
cache: { get: vi.fn(), set: vi.fn(), contains: vi.fn(), remove: vi.fn() },
146143
};
147144

148-
mockGetPollingConfigManager.mockImplementationOnce(() => {
149-
return getPollingConfigManager(config);
150-
});
151-
152145
MockReactNativeAsyncStorageCache.mockImplementationOnce(() => {
153146
return new ReactNativeAsyncStorageCache();
154147
});
@@ -159,9 +152,7 @@ describe('createPollingConfigManager', () => {
159152

160153
it('should throw an error if cache is not present in the config, and async storage is not available', async () => {
161154
isAsyncStorageAvailable = false;
162-
const { getPollingConfigManager } = await vi.importActual<typeof import('./config_manager_factory')>(
163-
'./config_manager_factory'
164-
);
155+
165156
const { default: ReactNativeAsyncStorageCache } = await vi.importActual<
166157
typeof import('../plugins/key_value_cache/reactNativeAsyncStorageCache')
167158
>('../plugins/key_value_cache/reactNativeAsyncStorageCache');
@@ -170,10 +161,6 @@ describe('createPollingConfigManager', () => {
170161
requestHandler: { makeRequest: vi.fn() },
171162
};
172163

173-
mockGetPollingConfigManager.mockImplementationOnce(() => {
174-
return getPollingConfigManager(config);
175-
});
176-
177164
MockReactNativeAsyncStorageCache.mockImplementationOnce(() => {
178165
return new ReactNativeAsyncStorageCache();
179166
});

lib/project_config/config_manager_factory.react_native.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
import { getPollingConfigManager, PollingConfigManagerConfig } from "./config_manager_factory";
1818
import { BrowserRequestHandler } from "../utils/http_request_handler/browser_request_handler";
1919
import { ProjectConfigManager } from "./project_config_manager";
20+
import ReactNativeAsyncStorageCache from "../plugins/key_value_cache/reactNativeAsyncStorageCache";
2021

2122
export const createPollingProjectConfigManager = (config: PollingConfigManagerConfig): ProjectConfigManager => {
2223
const defaultConfig = {
2324
autoUpdate: true,
2425
requestHandler: new BrowserRequestHandler(),
26+
cache: config.cache || new ReactNativeAsyncStorageCache()
2527
};
28+
2629
return getPollingConfigManager({ ...defaultConfig, ...config });
2730
};

lib/project_config/config_manager_factory.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { PollingDatafileManager } from "./polling_datafile_manager";
2222
import PersistentKeyValueCache from "../plugins/key_value_cache/persistentKeyValueCache";
2323
import { DEFAULT_UPDATE_INTERVAL } from './constant';
2424
import { ExponentialBackoff, IntervalRepeater } from "../utils/repeater/repeater";
25-
import ReactNativeAsyncStorageCache from "../plugins/key_value_cache/reactNativeAsyncStorageCache";
2625

2726
export type StaticConfigManagerConfig = {
2827
datafile: string,
@@ -63,7 +62,7 @@ export const getPollingConfigManager = (
6362
urlTemplate: opt.urlTemplate,
6463
datafileAccessToken: opt.datafileAccessToken,
6564
requestHandler: opt.requestHandler,
66-
cache: opt.cache || new ReactNativeAsyncStorageCache(),
65+
cache: opt.cache,
6766
repeater,
6867
};
6968

0 commit comments

Comments
 (0)