Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('handles upsert race condition against other client with lower version', async () => {
var myDesiredVersion = 10;
var competingStoreVersions = [ 2, 3, 4 ]; // proves that we can retry multiple times if necessary
var myStore = makeStoreWithHook(writeCompetingVersions(competingStoreVersions));
await initStore(myStore);
await promisifySingle(myStore.upsert)(dataKind.features, makeFlagWithVersion(myDesiredVersion));
var result = await promisifySingle(myStore.get)(dataKind.features, flagKey);
expect(result.version).toEqual(myDesiredVersion);
});
it('does not get nonexisting feature', async () => {
var store = await initedStore();
var result = await promisifySingle(store.get)(dataKind.features, 'biz');
expect(result).toBe(null);
});
it('does not delete with older version', async () => {
var store = await initedStore();
await promisifySingle(store.delete)(dataKind.features, feature1.key, feature1.version - 1);
var result = await promisifySingle(store.get)(dataKind.features, feature1.key);
expect(result).not.toBe(null);
});
it('init() completely replaces previous data', async () => {
var store = makeStore();
var flags = {
first: { key: 'first', version: 1 },
second: { key: 'second', version: 1 }
};
var segments = { first: { key: 'first', version: 2 } };
var initData = {};
initData[dataKind.features.namespace] = flags;
initData[dataKind.segments.namespace] = segments;
await promisifySingle(store.init)(initData);
var items = await promisifySingle(store.all)(dataKind.features);
expect(items).toEqual(flags);
items = await promisifySingle(store.all)(dataKind.segments);
expect(items).toEqual(segments);
var newFlags = { first: { key: 'first', version: 3 } };
var newSegments = { first: { key: 'first', version: 4 } };
var initData = {};
initData[dataKind.features.namespace] = newFlags;
initData[dataKind.segments.namespace] = newSegments;
await promisifySingle(store.init)(initData);
items = await promisifySingle(store.all)(dataKind.features);
expect(items).toEqual(newFlags);
items = await promisifySingle(store.all)(dataKind.segments);
expect(items).toEqual(newSegments);
});
it(desc, async () => {
var store1 = makeStore();
var store2 = makeStore();
var result = await promisifySingle(store1.initialized)();
expect(result).toBe(false);
await promisifySingle(store2.init)(initData);
result = await promisifySingle(store1.initialized)();
expect(result).toBe(true);
});
}
async function initStore(store) {
var allData = { features: {} };
allData['features'][flagKey] = makeFlagWithVersion(initialVersion);
await promisifySingle(store.init)(allData);
}
async function initedStore() {
var store = makeStore();
var initData = {};
initData[dataKind.features.namespace] = {
'foo': feature1,
'bar': feature2
};
await promisifySingle(store.init)(initData);
return store;
}