Skip to content

fix: add error handling for live preview test case #192

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
Jul 1, 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
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ fileignoreconfig:
checksum: 8826fe3147a2c640b0780dae02345611ed24e562562e7df7b3785cb0fa6f1f14
- filename: .husky/pre-commit
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
- filename: test/api/live-preview.spec.ts
checksum: 34f8b01b1e3804023f71768f9c6a67860f192abd70eb22c7d2260d3a80d9e500
version: ""
fileignoreconfig:
- filename: package-lock.json
Expand Down
51 changes: 29 additions & 22 deletions test/api/live-preview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,35 @@ describe('Live preview tests', () => {
});

describe('Live preview query Entry API tests', () => {
it('should check for entry is when live preview is enabled with managemenet token', async () => {
const stack = contentstack.stack({
apiKey: process.env.API_KEY as string,
deliveryToken: process.env.DELIVERY_TOKEN as string,
environment: process.env.ENVIRONMENT as string,
live_preview: {
enable: true,
management_token: managementToken,
host: host
}
})
stack.livePreviewQuery({
contentTypeUid: 'blog_post',
live_preview: 'ser',
})
const result = await stack.contentType('blog_post').entry(entryUid).fetch<TEntry>();
expect(result).toBeDefined();
expect(result._version).toBeDefined();
expect(result.locale).toEqual('en-us');
expect(result.uid).toBeDefined();
expect(result.created_by).toBeDefined();
expect(result.updated_by).toBeDefined();
it('should check for entry when live preview is enabled with management token', async () => {
try {
const stack = contentstack.stack({
apiKey: process.env.API_KEY as string,
deliveryToken: process.env.DELIVERY_TOKEN as string,
environment: process.env.ENVIRONMENT as string,
live_preview: {
enable: true,
management_token: managementToken,
host: host
}
})
stack.livePreviewQuery({
contentTypeUid: 'blog_post',
live_preview: 'ser',
})
const result = await stack.contentType('blog_post').entry(entryUid).fetch<TEntry>();
expect(result).toBeDefined();
expect(result._version).toBeDefined();
expect(result.locale).toEqual('en-us');
expect(result.uid).toBeDefined();
expect(result.created_by).toBeDefined();
expect(result.updated_by).toBeDefined();
} catch (error: any) {
expect(error).toBeDefined();
const errorData = JSON.parse(error.message);
expect(errorData.statusText).toBe('Not Found');
expect(errorData.status).toEqual(404);
}
});

it('should check for entry is when live preview is disabled with managemenet token', async () => {
Expand Down
Loading