@ringcentral/sdk
Version:
- [Installation](#installation) - [Getting Started](#getting-started) - [API Calls](#api-calls) - [Advanced SDK Configuration & Polyfills](#advanced-sdk-configuration--polyfills) - [Making telephony calls](#making-telephony-calls) - [Call management using
68 lines (51 loc) • 1.97 kB
text/typescript
import {asyncTest, expect, createSdk} from '../test/test';
describe('RingCentral.core.Cache', () => {
describe('getItem', () => {
it(
'returns null if item not found',
asyncTest(async sdk => {
const cache = sdk.cache();
expect(await cache.getItem('foo')).to.equal(null);
}),
);
});
describe('setItem', () => {
it(
'sets an item in storage',
asyncTest(async sdk => {
const cache = sdk.cache();
const json = {foo: 'bar'};
await cache.setItem('foo', json);
expect(await cache.getItem('foo')).to.deep.equal(json);
await cache.removeItem('foo');
expect(await cache.getItem('foo')).to.equal(null);
}),
);
});
describe('clean', () => {
it(
'removes all prefixed entries from cache leaving non-prefixed ones untouched',
asyncTest(async sdk => {
const cache = sdk.cache();
cache['_externals'].localStorage.setItem('rc-foo', '"foo"');
cache['_externals'].localStorage.setItem('foo', '"foo"');
expect(await cache.getItem('foo')).to.equal('foo');
await cache.clean();
expect(await cache.getItem('foo')).to.equal(null);
// prettier-ignore
expect(cache['_externals'].localStorage.getItem('foo')).to.equal('"foo"');
}),
);
});
describe('prefix', () => {
it(
'different prefixes dont overlap',
asyncTest(async sdk1 => {
const sdk2 = createSdk({cachePrefix: 'foo'});
const cache1 = sdk1.cache();
await cache1.setItem('foo', {foo: 'bar'});
expect(await sdk2.cache().getItem('foo')).to.equal(null);
}),
);
});
});