Skip to content

Commit 97da918

Browse files
Merge pull request #117 from contentstack/development
Hotfix 2 | fix for live preview params issue
2 parents 2ebd2b2 + 541cc53 commit 97da918

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

src/lib/stack.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,11 @@ export class Stack {
159159
};
160160
} else {
161161
livePreviewParams = {
162-
live_preview: null,
163-
contentTypeUid: null,
164-
entryUid: null,
165-
preview_timestamp: null,
162+
...livePreviewParams,
163+
live_preview: "",
164+
contentTypeUid: "",
165+
entryUid: "",
166+
preview_timestamp: "",
166167
include_applied_variants: false,
167168
};
168169
}

test/unit/cache.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ describe('Cache handleRequest function', () => {
2828
describe('NETWORK_ELSE_CACHE policy', () => {
2929
it('should return network response when proper response is received', async () => {
3030
const cacheOptions = { policy: Policy.NETWORK_ELSE_CACHE, maxAge: 3600 };
31-
const defaultAdapter = jest.fn((_config) => ({ data: 'foo' }));
31+
const defaultAdapter = jest.fn((_config) => ({ data: JSON.stringify('foo') }));
3232
const cacheStore = new PersistanceStore(cacheOptions);
3333

3434
await handleRequest(cacheOptions, apiKey, defaultAdapter, resolve, reject, config);
3535

3636
expect(defaultAdapter).toHaveBeenCalledWith(config);
37-
expect(resolve).toBeCalledWith('foo');
37+
expect(resolve).toBeCalledWith({"data": "foo"});
3838
expect(reject).not.toBeCalled();
3939

4040
cacheStore.removeItem(apiKey, config.contentTypeUid);
@@ -97,14 +97,14 @@ describe('Cache handleRequest function', () => {
9797
});
9898
it('should return api response when proper cache is not available', async () => {
9999
const cacheOptions = { policy: Policy.CACHE_THEN_NETWORK, maxAge: 3600 };
100-
const defaultAdapter = jest.fn((_config) => ({ data: 'foo' }));
100+
const defaultAdapter = jest.fn((_config) => ({ data: JSON.stringify('foo') }));
101101

102102
const cacheStore = new PersistanceStore(cacheOptions);
103103

104104
await handleRequest(cacheOptions, apiKey, defaultAdapter, resolve, reject, config);
105105

106106
expect(defaultAdapter).toHaveBeenCalled();
107-
expect(resolve).toBeCalledWith('foo');
107+
expect(resolve).toBeCalledWith({"data": "foo"});
108108
expect(reject).not.toBeCalled();
109109

110110
cacheStore.removeItem(apiKey, config.contentTypeUid);
@@ -150,13 +150,13 @@ describe('Cache handleRequest function', () => {
150150

151151
it('should return network response data when cache is not available', async () => {
152152
const cacheOptions = { policy: Policy.CACHE_ELSE_NETWORK, maxAge: 3600 };
153-
const defaultAdapter = jest.fn((_config) => ({ data: 'foo' }));
153+
const defaultAdapter = jest.fn((_config) => ({ data: JSON.stringify('foo') }));
154154
const cacheStore = new PersistanceStore(cacheOptions);
155155

156156
await handleRequest(cacheOptions, apiKey, defaultAdapter, resolve, reject, config);
157157

158158
expect(defaultAdapter).toHaveBeenCalledWith(config);
159-
expect(resolve).toBeCalledWith('foo');
159+
expect(resolve).toBeCalledWith({"data": "foo"});
160160
expect(reject).not.toBeCalled();
161161

162162
cacheStore.removeItem(apiKey, config.contentTypeUid);

test/unit/persistance/preference-store.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@ describe('persistance store intiialization test', () => {
77
expect(persistance).toBeDefined();
88
expect(persistance.config).toBeDefined();
99
expect(persistance.config.maxAge).toEqual(86400000);
10-
expect(persistance.config.storageType).toEqual('localStorage');
10+
expect(persistance.config.storeType).toEqual('localStorage');
1111
});
1212

1313
it('should initialize persistance with name and local storage type ', () => {
14-
const storageType = 'localStorage';
15-
const persistance = makePersistance({ storageType });
14+
const storeType = 'localStorage';
15+
const persistance = makePersistance({ storeType });
1616
expect(persistance).toBeDefined();
1717
expect(persistance.config).toBeDefined();
1818
expect(persistance.config.maxAge).toEqual(86400000);
19-
expect(persistance.config.storageType).toEqual(storageType);
19+
expect(persistance.config.storeType).toEqual(storeType);
2020
});
2121
it('should initialize persistance with name and memory storage type ', () => {
22-
const storageType = 'memoryStorage';
23-
const persistance = makePersistance({ storageType });
22+
const storeType = 'memoryStorage';
23+
const persistance = makePersistance({ storeType });
2424
expect(persistance).toBeDefined();
2525
expect(persistance.config).toBeDefined();
2626
expect(persistance.config.maxAge).toEqual(86400000);
27-
expect(persistance.config.storageType).toEqual(storageType);
27+
expect(persistance.config.storeType).toEqual(storeType);
2828
});
2929
it('should initialize persistance with name and local storage type ', () => {
30-
const storageType = 'customStorage';
31-
const persistance = makePersistance({ storageType });
30+
const storeType = 'customStorage';
31+
const persistance = makePersistance({ storeType });
3232
expect(persistance).toBeDefined();
3333
expect(persistance.config).toBeDefined();
3434
expect(persistance.config.maxAge).toEqual(86400000);
35-
expect(persistance.config.storageType).toEqual(storageType);
35+
expect(persistance.config.storeType).toEqual(storeType);
3636
});
3737
it('should throw error on custom storage without storage', () => {
38-
const config: any = { name: 'foobar', storageType: 'customStorage' };
38+
const config: any = { name: 'foobar', storeType: 'customStorage' };
3939
config.storage = '';
4040
const persistance = () => {
4141
new PersistanceStore(config);
@@ -162,6 +162,6 @@ describe('persistance with 0 maxAge', () => {
162162
});
163163
});
164164

165-
function makePersistance(config: { storageType: StorageType | 'customStorage' }) {
166-
return new PersistanceStore({ storageType: config.storageType, storage: memoryStorage });
165+
function makePersistance(config: { storeType: StorageType | 'customStorage' }) {
166+
return new PersistanceStore({ storeType: config.storeType, storage: memoryStorage });
167167
}

test/unit/stack.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ describe('Stack class tests', () => {
9696
stack.livePreviewQuery(query);
9797

9898
expect(stack.getClient().stackConfig.live_preview).toEqual({
99-
live_preview: null,
100-
contentTypeUid: null,
101-
entryUid: null,
102-
preview_timestamp: null,
99+
live_preview: '',
100+
contentTypeUid: '',
101+
entryUid: '',
102+
enable: false,
103+
preview_timestamp: '',
103104
include_applied_variants: false,
104105
});
105106
});

0 commit comments

Comments
 (0)