Skip to content

Commit

Permalink
Flagsmith#201 (fix): new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oluizcarvalho committed Sep 12, 2024
1 parent d1cbaa1 commit e1582c7
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions test/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Sample test
import {
defaultState,
defaultStateAlt, FLAGSMITH_KEY,
defaultStateAlt,
FLAGSMITH_KEY,
getFlagsmith,
getStateToCheck,
identityState,
Expand Down Expand Up @@ -179,24 +180,7 @@ describe('Cache', () => {
...defaultStateAlt,
});
});
test('should not get flags from API when skipAPI is set', async () => {
const onChange = jest.fn();
const { flagsmith, initConfig, AsyncStorage, mockFetch } = getFlagsmith({
cacheFlags: true,
onChange,
cacheOptions: { ttl: 1000, skipAPI: true },
});
await AsyncStorage.setItem('BULLET_TRAIN_DB', JSON.stringify({
...defaultStateAlt,
ts: new Date().valueOf(),
}));
await flagsmith.init(initConfig);
expect(onChange).toHaveBeenCalledTimes(1);
expect(mockFetch).toHaveBeenCalledTimes(0);
expect(getStateToCheck(flagsmith.getState())).toEqual({
...defaultStateAlt,
});
});

test('should validate flags are unchanged when fetched', async () => {
const onChange = jest.fn();
const { flagsmith, initConfig, AsyncStorage, mockFetch } = getFlagsmith({
Expand Down Expand Up @@ -322,7 +306,7 @@ describe('Cache', () => {
preventFetch: true,
});
const storage = new SyncStorageMock();
await storage.setItem('BULLET_TRAIN_DB', JSON.stringify({
await storage.setItem(FLAGSMITH_KEY, JSON.stringify({
...identityState,
}));
const ts = Date.now();
Expand All @@ -333,7 +317,7 @@ describe('Cache', () => {
});
expect(flagsmith.getAllTraits()).toEqual({
...identityState.traits,
ts
})
ts,
});
});
});

0 comments on commit e1582c7

Please sign in to comment.