Skip to content

Commit 35f368e

Browse files
test: ✅ unit and api test cases for lp 1.0 and 2.0
1 parent f335fda commit 35f368e

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

test/api/live-preview.spec.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import * as contentstack from '../../src/lib/contentstack';
2+
import dotenv from 'dotenv';
3+
4+
dotenv.config();
5+
6+
const apiKey = process.env.API_KEY as string
7+
const deliveryToken = process.env.DELIVERY_TOKEN as string
8+
const environment = process.env.ENVIRONMENT as string
9+
10+
describe('Live preview tests', () => {
11+
test('should check for values initialized', () => {
12+
const stack = contentstack.Stack({
13+
apiKey: apiKey,
14+
deliveryToken: deliveryToken,
15+
environment: environment,
16+
});
17+
const livePreviewObject = stack.config.live_preview;
18+
expect(livePreviewObject).toBeUndefined();
19+
expect(stack.config.host).toBe('cdn.contentstack.io');
20+
});
21+
22+
test('should check host when live preview is enabled and management token is provided', () => {
23+
const stack = contentstack.Stack({
24+
apiKey: apiKey,
25+
deliveryToken: deliveryToken,
26+
environment: environment,
27+
live_preview: {
28+
enable: true,
29+
management_token: 'management_token'
30+
}
31+
})
32+
const livePreviewObject = stack.config.live_preview
33+
expect(livePreviewObject).not.toBeUndefined();
34+
expect(livePreviewObject).toHaveProperty('enable');
35+
expect(livePreviewObject).toHaveProperty('host');
36+
expect(livePreviewObject).not.toHaveProperty('preview');
37+
expect(stack.config.host).toBe('api.contentstack.com');
38+
});
39+
40+
test('should check host when live preview is disabled and management token is provided', () => {
41+
const stack = contentstack.Stack({
42+
apiKey: apiKey,
43+
deliveryToken: deliveryToken,
44+
environment: environment,
45+
live_preview: {
46+
enable: false,
47+
management_token: 'management_token'
48+
}
49+
})
50+
const livePreviewObject = stack.config.live_preview
51+
expect(livePreviewObject).not.toBeUndefined();
52+
expect(livePreviewObject).toHaveProperty('enable');
53+
expect(livePreviewObject).not.toHaveProperty('host');
54+
expect(livePreviewObject).not.toHaveProperty('preview');
55+
expect(stack.config.host).toBe('cdn.contentstack.io');
56+
});
57+
58+
test('should check host when live preview is enabled and preview token is provided', () => {
59+
const stack = contentstack.Stack({
60+
apiKey: apiKey,
61+
deliveryToken: deliveryToken,
62+
environment: environment,
63+
live_preview: {
64+
enable: true,
65+
preview_token: 'preview_token'
66+
}
67+
})
68+
const livePreviewObject = stack.config.live_preview
69+
expect(livePreviewObject).not.toBeUndefined();
70+
expect(livePreviewObject).toHaveProperty('enable');
71+
expect(livePreviewObject).toHaveProperty('host');
72+
expect(livePreviewObject).not.toHaveProperty('preview');
73+
expect(stack.config.host).toBe('rest-preview.contentstack.com');
74+
});
75+
76+
test('should check host when live preview is disabled and preview token is provided', () => {
77+
const stack = contentstack.Stack({
78+
apiKey: apiKey,
79+
deliveryToken: deliveryToken,
80+
environment: environment,
81+
live_preview: {
82+
enable: false,
83+
preview_token: 'preview_token'
84+
}
85+
})
86+
const livePreviewObject = stack.config.live_preview
87+
expect(livePreviewObject).not.toBeUndefined();
88+
expect(livePreviewObject).toHaveProperty('enable');
89+
expect(livePreviewObject).not.toHaveProperty('host');
90+
expect(livePreviewObject).not.toHaveProperty('preview');
91+
expect(stack.config.host).toBe('cdn.contentstack.io');
92+
});
93+
});

test/unit/live-preview.spec.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import * as Contentstack from '../../src/lib/contentstack';
2+
3+
describe('Live preview tests', () => {
4+
5+
test('should check for values initialized', () => {
6+
const stack = Contentstack.Stack({
7+
apiKey: 'apiKey',
8+
deliveryToken: 'deliveryToken',
9+
environment: 'environment',
10+
});
11+
const livePreviewObject = stack.config.live_preview;
12+
expect(livePreviewObject).toBeUndefined();
13+
expect(stack.config.host).toBe('cdn.contentstack.io');
14+
});
15+
16+
test('should check host when live preview is enabled and management token is provided', () => {
17+
const stack = Contentstack.Stack({
18+
apiKey: 'apiKey',
19+
deliveryToken: 'deliveryToken',
20+
environment: 'environment',
21+
live_preview: {
22+
enable: true,
23+
management_token: 'management_token'
24+
}
25+
})
26+
const livePreviewObject = stack.config.live_preview
27+
expect(livePreviewObject).not.toBeUndefined();
28+
expect(livePreviewObject).toHaveProperty('enable');
29+
expect(livePreviewObject).toHaveProperty('host');
30+
expect(livePreviewObject).not.toHaveProperty('preview');
31+
expect(stack.config.host).toBe('api.contentstack.com');
32+
});
33+
34+
test('should check host when live preview is disabled and management token is provided', () => {
35+
const stack = Contentstack.Stack({
36+
apiKey: 'apiKey',
37+
deliveryToken: 'deliveryToken',
38+
environment: 'environment',
39+
live_preview: {
40+
enable: false,
41+
management_token: 'management_token'
42+
}
43+
})
44+
const livePreviewObject = stack.config.live_preview
45+
expect(livePreviewObject).not.toBeUndefined();
46+
expect(livePreviewObject).toHaveProperty('enable');
47+
expect(livePreviewObject).not.toHaveProperty('host');
48+
expect(livePreviewObject).not.toHaveProperty('preview');
49+
expect(stack.config.host).toBe('cdn.contentstack.io');
50+
});
51+
52+
test('should check host when live preview is enabled and preview token is provided', () => {
53+
const stack = Contentstack.Stack({
54+
apiKey: 'apiKey',
55+
deliveryToken: 'deliveryToken',
56+
environment: 'environment',
57+
live_preview: {
58+
enable: true,
59+
preview_token: 'preview_token'
60+
}
61+
})
62+
const livePreviewObject = stack.config.live_preview
63+
expect(livePreviewObject).not.toBeUndefined();
64+
expect(livePreviewObject).toHaveProperty('enable');
65+
expect(livePreviewObject).toHaveProperty('host');
66+
expect(livePreviewObject).not.toHaveProperty('preview');
67+
expect(stack.config.host).toBe('rest-preview.contentstack.com');
68+
});
69+
70+
test('should check host when live preview is disabled and preview token is provided', () => {
71+
const stack = Contentstack.Stack({
72+
apiKey: 'apiKey',
73+
deliveryToken: 'deliveryToken',
74+
environment: 'environment',
75+
live_preview: {
76+
enable: false,
77+
preview_token: 'preview_token'
78+
}
79+
})
80+
const livePreviewObject = stack.config.live_preview
81+
expect(livePreviewObject).not.toBeUndefined();
82+
expect(livePreviewObject).toHaveProperty('enable');
83+
expect(livePreviewObject).not.toHaveProperty('host');
84+
expect(livePreviewObject).not.toHaveProperty('preview');
85+
expect(stack.config.host).toBe('cdn.contentstack.io');
86+
});
87+
});

0 commit comments

Comments
 (0)