|
|
@@ -1,7 +1,7 @@
|
|
|
-import { CacheService, mergeConfig, RedisCachePlugin } from '@vendure/core';
|
|
|
+import { CacheService, Logger, mergeConfig, RedisCachePlugin } from '@vendure/core';
|
|
|
import { createTestEnvironment } from '@vendure/testing';
|
|
|
import path from 'path';
|
|
|
-import { afterAll, beforeAll, describe, it } from 'vitest';
|
|
|
+import { vi, afterAll, beforeAll, describe, it, expect } from 'vitest';
|
|
|
|
|
|
import { initialData } from '../../../e2e-common/e2e-initial-data';
|
|
|
import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
|
|
|
@@ -13,7 +13,10 @@ import {
|
|
|
invalidatesByMultipleTags,
|
|
|
invalidatesBySingleTag,
|
|
|
invalidatesManyByMultipleTags,
|
|
|
+ invalidTTLsShouldNotSetKey,
|
|
|
setsAKey,
|
|
|
+ setsAKeyWithSubSecondTtl,
|
|
|
+ setsAKeyWithTtl,
|
|
|
setsArrayOfObjects,
|
|
|
setsArrayValue,
|
|
|
setsObjectValue,
|
|
|
@@ -61,6 +64,30 @@ describe('CacheService with RedisCachePlugin', () => {
|
|
|
|
|
|
it('deletes a key', () => deletesAKey(cacheService));
|
|
|
|
|
|
+ it('sets a key with ttl', async () => {
|
|
|
+ await cacheService.set('test-key1', 'test-value', { ttl: 1000 });
|
|
|
+ const result = await cacheService.get('test-key1');
|
|
|
+ expect(result).toBe('test-value');
|
|
|
+
|
|
|
+ await new Promise(resolve => setTimeout(resolve, 1500));
|
|
|
+
|
|
|
+ const result2 = await cacheService.get('test-key1');
|
|
|
+
|
|
|
+ expect(result2).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('sets a key with sub-second ttl', async () => {
|
|
|
+ await cacheService.set('test-key2', 'test-value', { ttl: 900 });
|
|
|
+ const result = await cacheService.get('test-key2');
|
|
|
+ expect(result).toBe('test-value');
|
|
|
+
|
|
|
+ await new Promise(resolve => setTimeout(resolve, 1500));
|
|
|
+
|
|
|
+ const result2 = await cacheService.get('test-key2');
|
|
|
+
|
|
|
+ expect(result2).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
it('invalidates by single tag', () => invalidatesBySingleTag(cacheService));
|
|
|
|
|
|
it('invalidates by multiple tags', () => invalidatesByMultipleTags(cacheService));
|
|
|
@@ -68,4 +95,6 @@ describe('CacheService with RedisCachePlugin', () => {
|
|
|
it('invalidates many by multiple tags', () => invalidatesManyByMultipleTags(cacheService));
|
|
|
|
|
|
it('invalidates a large number of keys by tag', () => invalidatesALargeNumberOfKeysByTag(cacheService));
|
|
|
+
|
|
|
+ it('invalid ttls should not set key', () => invalidTTLsShouldNotSetKey(cacheService));
|
|
|
});
|