Skip to content

Hotfix 2 | fix for live preview params issue #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
Expand Down
12 changes: 6 additions & 6 deletions test/unit/cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 13 additions & 13 deletions test/unit/persistance/preference-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 });
}
9 changes: 5 additions & 4 deletions test/unit/stack.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
Expand Down
Loading