mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.6 KiB
64 lines
1.6 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Sebastian Stehle. All rights reserved
|
|
*/
|
|
|
|
import { LocalCacheService, LocalCacheServiceFactory } from './../';
|
|
|
|
describe('LocalCache', () => {
|
|
it('should instantiate from factory', () => {
|
|
const localCacheService = LocalCacheServiceFactory();
|
|
|
|
expect(localCacheService).toBeDefined();
|
|
});
|
|
|
|
it('should instantiate', () => {
|
|
const localCacheService = new LocalCacheService();
|
|
|
|
expect(localCacheService).toBeDefined();
|
|
});
|
|
|
|
it('should get and store item in cache', () => {
|
|
const localCacheService = new LocalCacheService();
|
|
|
|
const value = {};
|
|
|
|
localCacheService.set('key', value);
|
|
|
|
expect(localCacheService.get('key')).toBe(value);
|
|
});
|
|
|
|
it('should not retrieve item if cleared', () => {
|
|
const localCacheService = new LocalCacheService();
|
|
|
|
const value = {};
|
|
|
|
localCacheService.set('key', value);
|
|
localCacheService.clear(true);
|
|
|
|
expect(localCacheService.get('key')).toBeUndefined();
|
|
});
|
|
|
|
it('should not retrieve item if removed', () => {
|
|
const localCacheService = new LocalCacheService();
|
|
|
|
const value = {};
|
|
|
|
localCacheService.set('key', value);
|
|
localCacheService.remove('key');
|
|
|
|
expect(localCacheService.get('key')).toBeUndefined();
|
|
});
|
|
|
|
it('should not retrieve item if expired', () => {
|
|
const localCacheService = new LocalCacheService();
|
|
|
|
const value = {};
|
|
|
|
localCacheService.set('key', value);
|
|
|
|
expect(localCacheService.get('key', new Date().getTime() + 400)).toBeUndefined();
|
|
});
|
|
});
|