Skip to content

Merge staging to development #196

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 4 commits into from
Jul 3, 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
4 changes: 2 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ fileignoreconfig:
checksum: cadf177ffc4ce8c271e8b49fd227947351afa7cade5c7cd902cda78d0f91ba5b
- filename: test/unit/persistance/preference-store.spec.ts
checksum: 0f3457f8ea8b149c5de1d6585c78eb4cea0d2ac00ca69cdc294c44fe29ea3c11
- filename: test/api/live-preview.spec.ts
checksum: acdb1bd25dc81cfd9ea16e8a3e3960930c9e6e6034defd8552421e0d25e8afc4
- filename: test/unit/contentstack.spec.ts
checksum: 267e4857af531bd3e5f080c3630922169a0c161355a6b185f1ee2716c5e60c45
- filename: test/unit/utils.spec.ts
Expand All @@ -15,4 +13,6 @@ fileignoreconfig:
checksum: a5e87bfe625b8cef8714545c07cfbe3ea05b07c8cb495fef532c610b37d82140
- filename: test/unit/persistance/preference-store.spec.ts
checksum: 5d31522fb28b95b0b243b8f3d8499dcf4c5c80c0ea24f895802a724136985e37
- filename: test/api/live-preview.spec.ts
checksum: 42b72f54a8c51fc9f98c6044a78d1435388972522763af6bf36f066ff2dc555c
version: "1.0"
337 changes: 173 additions & 164 deletions test/api/live-preview.spec.ts
Original file line number Diff line number Diff line change
@@ -1,183 +1,192 @@
import * as contentstack from '../../src/lib/contentstack';
import { TEntry } from './types';
import dotenv from 'dotenv';
import * as contentstack from "../../src/lib/contentstack";
import { TEntry } from "./types";
import dotenv from "dotenv";

dotenv.config();

const apiKey = process.env.API_KEY as string
const deliveryToken = process.env.DELIVERY_TOKEN as string
const environment = process.env.ENVIRONMENT as string
const branch = process.env.BRANCH as string
const entryUid = process.env.ENTRY_UID as string
const previewToken = process.env.PREVIEW_TOKEN as string
const managementToken = process.env.MANAGEMENT_TOKEN as string
const host = process.env.HOST as string
const apiKey = process.env.API_KEY as string;
const deliveryToken = process.env.DELIVERY_TOKEN as string;
const environment = process.env.ENVIRONMENT as string;
const branch = process.env.BRANCH as string;
const entryUid = process.env.ENTRY_UID as string;
const previewToken = process.env.PREVIEW_TOKEN as string;
const managementToken = process.env.MANAGEMENT_TOKEN as string;
const host = process.env.HOST as string;

describe('Live preview tests', () => {
test('should check for values initialized', () => {
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
branch: branch,
});
const livePreviewObject = stack.config.live_preview;
expect(livePreviewObject).toBeUndefined();
expect(stack.config.host).toBe('cdn.contentstack.io');
expect(stack.config.branch).toBe(branch);
describe("Live preview tests", () => {
test("should check for values initialized", () => {
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
branch: branch,
});
const livePreviewObject = stack.config.live_preview;
expect(livePreviewObject).toBeUndefined();
expect(stack.config.host).toBe("cdn.contentstack.io");
expect(stack.config.branch).toBe(branch);
});

test('should check host when live preview is enabled and management token is provided', () => {
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
live_preview: {
enable: true,
management_token: managementToken,
host: host
}
})
const livePreviewObject = stack.config.live_preview
expect(livePreviewObject).not.toBeUndefined();
expect(livePreviewObject).toHaveProperty('enable');
expect(livePreviewObject).toHaveProperty('host');
expect(livePreviewObject).not.toHaveProperty('preview');
expect(stack.config.host).toBe('cdn.contentstack.io');
test("should check host when live preview is enabled and management token is provided", () => {
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
live_preview: {
enable: true,
management_token: managementToken,
host: host,
},
});
const livePreviewObject = stack.config.live_preview;
expect(livePreviewObject).not.toBeUndefined();
expect(livePreviewObject).toHaveProperty("enable");
expect(livePreviewObject).toHaveProperty("host");
expect(livePreviewObject).not.toHaveProperty("preview");
expect(stack.config.host).toBe("cdn.contentstack.io");
});

test('should check host when live preview is disabled and management token is provided', () => {
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
live_preview: {
enable: false,
management_token: managementToken
}
})
const livePreviewObject = stack.config.live_preview
expect(livePreviewObject).not.toBeUndefined();
expect(livePreviewObject).toHaveProperty('enable');
expect(livePreviewObject).not.toHaveProperty('host');
expect(livePreviewObject).not.toHaveProperty('preview');
expect(stack.config.host).toBe('cdn.contentstack.io');
test("should check host when live preview is disabled and management token is provided", () => {
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
live_preview: {
enable: false,
management_token: managementToken,
},
});
const livePreviewObject = stack.config.live_preview;
expect(livePreviewObject).not.toBeUndefined();
expect(livePreviewObject).toHaveProperty("enable");
expect(livePreviewObject).not.toHaveProperty("host");
expect(livePreviewObject).not.toHaveProperty("preview");
expect(stack.config.host).toBe("cdn.contentstack.io");
});

test('should check host when live preview is enabled and preview token is provided', () => {
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
live_preview: {
enable: true,
preview_token: previewToken,
host: host
}
})
const livePreviewObject = stack.config.live_preview
expect(livePreviewObject).not.toBeUndefined();
expect(livePreviewObject).toHaveProperty('enable');
expect(livePreviewObject).toHaveProperty('host');
expect(livePreviewObject).not.toHaveProperty('preview');
expect(stack.config.host).toBe('cdn.contentstack.io');
test("should check host when live preview is enabled and preview token is provided", () => {
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
live_preview: {
enable: true,
preview_token: previewToken,
host: host,
},
});
const livePreviewObject = stack.config.live_preview;
expect(livePreviewObject).not.toBeUndefined();
expect(livePreviewObject).toHaveProperty("enable");
expect(livePreviewObject).toHaveProperty("host");
expect(livePreviewObject).not.toHaveProperty("preview");
expect(stack.config.host).toBe("cdn.contentstack.io");
});

test('should check host when live preview is disabled and preview token is provided', () => {
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
live_preview: {
enable: false,
preview_token: previewToken
}
})
const livePreviewObject = stack.config.live_preview
expect(livePreviewObject).not.toBeUndefined();
expect(livePreviewObject).toHaveProperty('enable');
expect(livePreviewObject).not.toHaveProperty('host');
expect(livePreviewObject).not.toHaveProperty('preview');
expect(stack.config.host).toBe('cdn.contentstack.io');
test("should check host when live preview is disabled and preview token is provided", () => {
const stack = contentstack.stack({
apiKey: apiKey,
deliveryToken: deliveryToken,
environment: environment,
live_preview: {
enable: false,
preview_token: previewToken,
},
});
const livePreviewObject = stack.config.live_preview;
expect(livePreviewObject).not.toBeUndefined();
expect(livePreviewObject).toHaveProperty("enable");
expect(livePreviewObject).not.toHaveProperty("host");
expect(livePreviewObject).not.toHaveProperty("preview");
expect(stack.config.host).toBe("cdn.contentstack.io");
});
});

describe('Live preview query Entry API tests', () => {
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.status).toEqual(403);
}
});
describe("Live preview query Entry API tests", () => {
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.status).toEqual(403);
}
});

it('should check for entry is when live preview is disabled with managemenet token', async () => {
const stack = contentstack.stack({
host: process.env.HOST as string,
apiKey: process.env.API_KEY as string,
deliveryToken: process.env.DELIVERY_TOKEN as string,
environment: process.env.ENVIRONMENT as string,
live_preview: {
enable: false,
management_token: managementToken
}
})
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 is when live preview is disabled with management token", async () => {
const stack = contentstack.stack({
host: process.env.HOST as string,
apiKey: process.env.API_KEY as string,
deliveryToken: process.env.DELIVERY_TOKEN as string,
environment: process.env.ENVIRONMENT as string,
live_preview: {
enable: false,
management_token: managementToken,
},
});
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 is when live preview is disabled with preview token', async () => {
const stack = contentstack.stack({
host: process.env.HOST as string,
apiKey: process.env.API_KEY as string,
deliveryToken: process.env.DELIVERY_TOKEN as string,
environment: process.env.ENVIRONMENT as string,
live_preview: {
enable: false,
preview_token: previewToken
}
})
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 is when live preview is disabled with preview token", async () => {
const stack = contentstack.stack({
host: process.env.HOST as string,
apiKey: process.env.API_KEY as string,
deliveryToken: process.env.DELIVERY_TOKEN as string,
environment: process.env.ENVIRONMENT as string,
live_preview: {
enable: false,
preview_token: previewToken,
},
});
})
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();
});
});