diff --git a/src/lib/stack.ts b/src/lib/stack.ts index e4bfc561..a1f6e22a 100644 --- a/src/lib/stack.ts +++ b/src/lib/stack.ts @@ -159,10 +159,11 @@ export class Stack { }; } else { livePreviewParams = { - live_preview: null, - contentTypeUid: null, - entryUid: null, - preview_timestamp: null, + ...livePreviewParams, + live_preview: "", + contentTypeUid: "", + entryUid: "", + preview_timestamp: "", include_applied_variants: false, }; } diff --git a/test/unit/cache.spec.ts b/test/unit/cache.spec.ts index fd10d576..d1706dc0 100644 --- a/test/unit/cache.spec.ts +++ b/test/unit/cache.spec.ts @@ -28,13 +28,13 @@ describe('Cache handleRequest function', () => { describe('NETWORK_ELSE_CACHE policy', () => { it('should return network response when proper response is received', async () => { const cacheOptions = { policy: Policy.NETWORK_ELSE_CACHE, maxAge: 3600 }; - const defaultAdapter = jest.fn((_config) => ({ data: 'foo' })); + const defaultAdapter = jest.fn((_config) => ({ data: JSON.stringify('foo') })); const cacheStore = new PersistanceStore(cacheOptions); await handleRequest(cacheOptions, apiKey, defaultAdapter, resolve, reject, config); expect(defaultAdapter).toHaveBeenCalledWith(config); - expect(resolve).toBeCalledWith('foo'); + expect(resolve).toBeCalledWith({"data": "foo"}); expect(reject).not.toBeCalled(); cacheStore.removeItem(apiKey, config.contentTypeUid); @@ -97,14 +97,14 @@ describe('Cache handleRequest function', () => { }); it('should return api response when proper cache is not available', async () => { const cacheOptions = { policy: Policy.CACHE_THEN_NETWORK, maxAge: 3600 }; - const defaultAdapter = jest.fn((_config) => ({ data: 'foo' })); + const defaultAdapter = jest.fn((_config) => ({ data: JSON.stringify('foo') })); const cacheStore = new PersistanceStore(cacheOptions); await handleRequest(cacheOptions, apiKey, defaultAdapter, resolve, reject, config); expect(defaultAdapter).toHaveBeenCalled(); - expect(resolve).toBeCalledWith('foo'); + expect(resolve).toBeCalledWith({"data": "foo"}); expect(reject).not.toBeCalled(); cacheStore.removeItem(apiKey, config.contentTypeUid); @@ -150,13 +150,13 @@ describe('Cache handleRequest function', () => { it('should return network response data when cache is not available', async () => { const cacheOptions = { policy: Policy.CACHE_ELSE_NETWORK, maxAge: 3600 }; - const defaultAdapter = jest.fn((_config) => ({ data: 'foo' })); + const defaultAdapter = jest.fn((_config) => ({ data: JSON.stringify('foo') })); const cacheStore = new PersistanceStore(cacheOptions); await handleRequest(cacheOptions, apiKey, defaultAdapter, resolve, reject, config); expect(defaultAdapter).toHaveBeenCalledWith(config); - expect(resolve).toBeCalledWith('foo'); + expect(resolve).toBeCalledWith({"data": "foo"}); expect(reject).not.toBeCalled(); cacheStore.removeItem(apiKey, config.contentTypeUid); diff --git a/test/unit/persistance/preference-store.spec.ts b/test/unit/persistance/preference-store.spec.ts index f55997a6..40be6606 100644 --- a/test/unit/persistance/preference-store.spec.ts +++ b/test/unit/persistance/preference-store.spec.ts @@ -7,35 +7,35 @@ describe('persistance store intiialization test', () => { expect(persistance).toBeDefined(); expect(persistance.config).toBeDefined(); expect(persistance.config.maxAge).toEqual(86400000); - expect(persistance.config.storageType).toEqual('localStorage'); + expect(persistance.config.storeType).toEqual('localStorage'); }); it('should initialize persistance with name and local storage type ', () => { - const storageType = 'localStorage'; - const persistance = makePersistance({ storageType }); + const storeType = 'localStorage'; + const persistance = makePersistance({ storeType }); expect(persistance).toBeDefined(); expect(persistance.config).toBeDefined(); expect(persistance.config.maxAge).toEqual(86400000); - expect(persistance.config.storageType).toEqual(storageType); + expect(persistance.config.storeType).toEqual(storeType); }); it('should initialize persistance with name and memory storage type ', () => { - const storageType = 'memoryStorage'; - const persistance = makePersistance({ storageType }); + const storeType = 'memoryStorage'; + const persistance = makePersistance({ storeType }); expect(persistance).toBeDefined(); expect(persistance.config).toBeDefined(); expect(persistance.config.maxAge).toEqual(86400000); - expect(persistance.config.storageType).toEqual(storageType); + expect(persistance.config.storeType).toEqual(storeType); }); it('should initialize persistance with name and local storage type ', () => { - const storageType = 'customStorage'; - const persistance = makePersistance({ storageType }); + const storeType = 'customStorage'; + const persistance = makePersistance({ storeType }); expect(persistance).toBeDefined(); expect(persistance.config).toBeDefined(); expect(persistance.config.maxAge).toEqual(86400000); - expect(persistance.config.storageType).toEqual(storageType); + expect(persistance.config.storeType).toEqual(storeType); }); it('should throw error on custom storage without storage', () => { - const config: any = { name: 'foobar', storageType: 'customStorage' }; + const config: any = { name: 'foobar', storeType: 'customStorage' }; config.storage = ''; const persistance = () => { new PersistanceStore(config); @@ -162,6 +162,6 @@ describe('persistance with 0 maxAge', () => { }); }); -function makePersistance(config: { storageType: StorageType | 'customStorage' }) { - return new PersistanceStore({ storageType: config.storageType, storage: memoryStorage }); +function makePersistance(config: { storeType: StorageType | 'customStorage' }) { + return new PersistanceStore({ storeType: config.storeType, storage: memoryStorage }); } diff --git a/test/unit/stack.spec.ts b/test/unit/stack.spec.ts index ca955188..bc6dd0b3 100644 --- a/test/unit/stack.spec.ts +++ b/test/unit/stack.spec.ts @@ -96,10 +96,11 @@ describe('Stack class tests', () => { stack.livePreviewQuery(query); expect(stack.getClient().stackConfig.live_preview).toEqual({ - live_preview: null, - contentTypeUid: null, - entryUid: null, - preview_timestamp: null, + live_preview: '', + contentTypeUid: '', + entryUid: '', + enable: false, + preview_timestamp: '', include_applied_variants: false, }); });