Skip to content

Commit 29ff749

Browse files
committed
Merge staging to development
1 parent f4664a2 commit 29ff749

File tree

1 file changed

+174
-164
lines changed

1 file changed

+174
-164
lines changed

test/api/live-preview.spec.ts

Lines changed: 174 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,183 +1,193 @@
1-
import * as contentstack from '../../src/lib/contentstack';
2-
import { TEntry } from './types';
3-
import dotenv from 'dotenv';
1+
import * as contentstack from "../../src/lib/contentstack";
2+
import { TEntry } from "./types";
3+
import dotenv from "dotenv";
44

55
dotenv.config();
66

7-
const apiKey = process.env.API_KEY as string
8-
const deliveryToken = process.env.DELIVERY_TOKEN as string
9-
const environment = process.env.ENVIRONMENT as string
10-
const branch = process.env.BRANCH as string
11-
const entryUid = process.env.ENTRY_UID as string
12-
const previewToken = process.env.PREVIEW_TOKEN as string
13-
const managementToken = process.env.MANAGEMENT_TOKEN as string
14-
const host = process.env.HOST as string
7+
const apiKey = process.env.API_KEY as string;
8+
const deliveryToken = process.env.DELIVERY_TOKEN as string;
9+
const environment = process.env.ENVIRONMENT as string;
10+
const branch = process.env.BRANCH as string;
11+
const entryUid = process.env.ENTRY_UID as string;
12+
const previewToken = process.env.PREVIEW_TOKEN as string;
13+
const managementToken = process.env.MANAGEMENT_TOKEN as string;
14+
const host = process.env.HOST as string;
1515

16-
describe('Live preview tests', () => {
17-
test('should check for values initialized', () => {
18-
const stack = contentstack.stack({
19-
apiKey: apiKey,
20-
deliveryToken: deliveryToken,
21-
environment: environment,
22-
branch: branch,
23-
});
24-
const livePreviewObject = stack.config.live_preview;
25-
expect(livePreviewObject).toBeUndefined();
26-
expect(stack.config.host).toBe('cdn.contentstack.io');
27-
expect(stack.config.branch).toBe(branch);
16+
describe("Live preview tests", () => {
17+
test("should check for values initialized", () => {
18+
const stack = contentstack.stack({
19+
apiKey: apiKey,
20+
deliveryToken: deliveryToken,
21+
environment: environment,
22+
branch: branch,
2823
});
24+
const livePreviewObject = stack.config.live_preview;
25+
expect(livePreviewObject).toBeUndefined();
26+
expect(stack.config.host).toBe("cdn.contentstack.io");
27+
expect(stack.config.branch).toBe(branch);
28+
});
2929

30-
test('should check host when live preview is enabled and management token is provided', () => {
31-
const stack = contentstack.stack({
32-
apiKey: apiKey,
33-
deliveryToken: deliveryToken,
34-
environment: environment,
35-
live_preview: {
36-
enable: true,
37-
management_token: managementToken,
38-
host: host
39-
}
40-
})
41-
const livePreviewObject = stack.config.live_preview
42-
expect(livePreviewObject).not.toBeUndefined();
43-
expect(livePreviewObject).toHaveProperty('enable');
44-
expect(livePreviewObject).toHaveProperty('host');
45-
expect(livePreviewObject).not.toHaveProperty('preview');
46-
expect(stack.config.host).toBe('cdn.contentstack.io');
30+
test("should check host when live preview is enabled and management token is provided", () => {
31+
const stack = contentstack.stack({
32+
apiKey: apiKey,
33+
deliveryToken: deliveryToken,
34+
environment: environment,
35+
live_preview: {
36+
enable: true,
37+
management_token: managementToken,
38+
host: host,
39+
},
4740
});
41+
const livePreviewObject = stack.config.live_preview;
42+
expect(livePreviewObject).not.toBeUndefined();
43+
expect(livePreviewObject).toHaveProperty("enable");
44+
expect(livePreviewObject).toHaveProperty("host");
45+
expect(livePreviewObject).not.toHaveProperty("preview");
46+
expect(stack.config.host).toBe("cdn.contentstack.io");
47+
});
4848

49-
test('should check host when live preview is disabled and management token is provided', () => {
50-
const stack = contentstack.stack({
51-
apiKey: apiKey,
52-
deliveryToken: deliveryToken,
53-
environment: environment,
54-
live_preview: {
55-
enable: false,
56-
management_token: managementToken
57-
}
58-
})
59-
const livePreviewObject = stack.config.live_preview
60-
expect(livePreviewObject).not.toBeUndefined();
61-
expect(livePreviewObject).toHaveProperty('enable');
62-
expect(livePreviewObject).not.toHaveProperty('host');
63-
expect(livePreviewObject).not.toHaveProperty('preview');
64-
expect(stack.config.host).toBe('cdn.contentstack.io');
49+
test("should check host when live preview is disabled and management token is provided", () => {
50+
const stack = contentstack.stack({
51+
apiKey: apiKey,
52+
deliveryToken: deliveryToken,
53+
environment: environment,
54+
live_preview: {
55+
enable: false,
56+
management_token: managementToken,
57+
},
6558
});
59+
const livePreviewObject = stack.config.live_preview;
60+
expect(livePreviewObject).not.toBeUndefined();
61+
expect(livePreviewObject).toHaveProperty("enable");
62+
expect(livePreviewObject).not.toHaveProperty("host");
63+
expect(livePreviewObject).not.toHaveProperty("preview");
64+
expect(stack.config.host).toBe("cdn.contentstack.io");
65+
});
6666

67-
test('should check host when live preview is enabled and preview token is provided', () => {
68-
const stack = contentstack.stack({
69-
apiKey: apiKey,
70-
deliveryToken: deliveryToken,
71-
environment: environment,
72-
live_preview: {
73-
enable: true,
74-
preview_token: previewToken,
75-
host: host
76-
}
77-
})
78-
const livePreviewObject = stack.config.live_preview
79-
expect(livePreviewObject).not.toBeUndefined();
80-
expect(livePreviewObject).toHaveProperty('enable');
81-
expect(livePreviewObject).toHaveProperty('host');
82-
expect(livePreviewObject).not.toHaveProperty('preview');
83-
expect(stack.config.host).toBe('cdn.contentstack.io');
67+
test("should check host when live preview is enabled and preview token is provided", () => {
68+
const stack = contentstack.stack({
69+
apiKey: apiKey,
70+
deliveryToken: deliveryToken,
71+
environment: environment,
72+
live_preview: {
73+
enable: true,
74+
preview_token: previewToken,
75+
host: host,
76+
},
8477
});
78+
const livePreviewObject = stack.config.live_preview;
79+
expect(livePreviewObject).not.toBeUndefined();
80+
expect(livePreviewObject).toHaveProperty("enable");
81+
expect(livePreviewObject).toHaveProperty("host");
82+
expect(livePreviewObject).not.toHaveProperty("preview");
83+
expect(stack.config.host).toBe("cdn.contentstack.io");
84+
});
8585

86-
test('should check host when live preview is disabled and preview token is provided', () => {
87-
const stack = contentstack.stack({
88-
apiKey: apiKey,
89-
deliveryToken: deliveryToken,
90-
environment: environment,
91-
live_preview: {
92-
enable: false,
93-
preview_token: previewToken
94-
}
95-
})
96-
const livePreviewObject = stack.config.live_preview
97-
expect(livePreviewObject).not.toBeUndefined();
98-
expect(livePreviewObject).toHaveProperty('enable');
99-
expect(livePreviewObject).not.toHaveProperty('host');
100-
expect(livePreviewObject).not.toHaveProperty('preview');
101-
expect(stack.config.host).toBe('cdn.contentstack.io');
86+
test("should check host when live preview is disabled and preview token is provided", () => {
87+
const stack = contentstack.stack({
88+
apiKey: apiKey,
89+
deliveryToken: deliveryToken,
90+
environment: environment,
91+
live_preview: {
92+
enable: false,
93+
preview_token: previewToken,
94+
},
10295
});
96+
const livePreviewObject = stack.config.live_preview;
97+
expect(livePreviewObject).not.toBeUndefined();
98+
expect(livePreviewObject).toHaveProperty("enable");
99+
expect(livePreviewObject).not.toHaveProperty("host");
100+
expect(livePreviewObject).not.toHaveProperty("preview");
101+
expect(stack.config.host).toBe("cdn.contentstack.io");
102+
});
103103
});
104104

105-
describe('Live preview query Entry API tests', () => {
106-
it('should check for entry when live preview is enabled with management token', async () => {
107-
try {
108-
const stack = contentstack.stack({
109-
apiKey: process.env.API_KEY as string,
110-
deliveryToken: process.env.DELIVERY_TOKEN as string,
111-
environment: process.env.ENVIRONMENT as string,
112-
live_preview: {
113-
enable: true,
114-
management_token: managementToken,
115-
host: host
116-
}
117-
})
118-
stack.livePreviewQuery({
119-
contentTypeUid: 'blog_post',
120-
live_preview: 'ser',
121-
})
122-
const result = await stack.contentType('blog_post').entry(entryUid).fetch<TEntry>();
123-
expect(result).toBeDefined();
124-
expect(result._version).toBeDefined();
125-
expect(result.locale).toEqual('en-us');
126-
expect(result.uid).toBeDefined();
127-
expect(result.created_by).toBeDefined();
128-
expect(result.updated_by).toBeDefined();
129-
} catch (error: any) {
130-
expect(error).toBeDefined();
131-
const errorData = JSON.parse(error.message);
132-
expect(errorData.status).toEqual(403);
133-
}
134-
});
105+
describe("Live preview query Entry API tests", () => {
106+
it("should check for entry when live preview is enabled with management token", async () => {
107+
try {
108+
const stack = contentstack.stack({
109+
apiKey: process.env.API_KEY as string,
110+
deliveryToken: process.env.DELIVERY_TOKEN as string,
111+
environment: process.env.ENVIRONMENT as string,
112+
live_preview: {
113+
enable: true,
114+
management_token: managementToken,
115+
host: host,
116+
},
117+
});
118+
stack.livePreviewQuery({
119+
contentTypeUid: "blog_post",
120+
live_preview: "ser",
121+
});
122+
const result = await stack
123+
.contentType("blog_post")
124+
.entry(entryUid)
125+
.fetch<TEntry>();
126+
expect(result).toBeDefined();
127+
expect(result._version).toBeDefined();
128+
expect(result.locale).toEqual("en-us");
129+
expect(result.uid).toBeDefined();
130+
expect(result.created_by).toBeDefined();
131+
expect(result.updated_by).toBeDefined();
132+
} catch (error: any) {
133+
expect(error).toBeDefined();
134+
const errorData = JSON.parse(error.message);
135+
expect(errorData.statusText).toBe("Not Found");
136+
expect(errorData.status).toEqual(404);
137+
}
138+
});
135139

136-
it('should check for entry is when live preview is disabled with managemenet token', async () => {
137-
const stack = contentstack.stack({
138-
host: process.env.HOST as string,
139-
apiKey: process.env.API_KEY as string,
140-
deliveryToken: process.env.DELIVERY_TOKEN as string,
141-
environment: process.env.ENVIRONMENT as string,
142-
live_preview: {
143-
enable: false,
144-
management_token: managementToken
145-
}
146-
})
147-
stack.livePreviewQuery({
148-
contentTypeUid: 'blog_post',
149-
live_preview: 'ser',
150-
})
151-
const result = await stack.contentType('blog_post').entry(entryUid).fetch<TEntry>();
152-
expect(result).toBeDefined();
153-
expect(result._version).toBeDefined();
154-
expect(result.locale).toEqual('en-us');
155-
expect(result.uid).toBeDefined();
156-
expect(result.created_by).toBeDefined();
157-
expect(result.updated_by).toBeDefined();
140+
it("should check for entry is when live preview is disabled with managemenet token", async () => {
141+
const stack = contentstack.stack({
142+
host: process.env.HOST as string,
143+
apiKey: process.env.API_KEY as string,
144+
deliveryToken: process.env.DELIVERY_TOKEN as string,
145+
environment: process.env.ENVIRONMENT as string,
146+
live_preview: {
147+
enable: false,
148+
management_token: managementToken,
149+
},
150+
});
151+
stack.livePreviewQuery({
152+
contentTypeUid: "blog_post",
153+
live_preview: "ser",
158154
});
155+
const result = await stack
156+
.contentType("blog_post")
157+
.entry(entryUid)
158+
.fetch<TEntry>();
159+
expect(result).toBeDefined();
160+
expect(result._version).toBeDefined();
161+
expect(result.locale).toEqual("en-us");
162+
expect(result.uid).toBeDefined();
163+
expect(result.created_by).toBeDefined();
164+
expect(result.updated_by).toBeDefined();
165+
});
159166

160-
it('should check for entry is when live preview is disabled with preview token', async () => {
161-
const stack = contentstack.stack({
162-
host: process.env.HOST as string,
163-
apiKey: process.env.API_KEY as string,
164-
deliveryToken: process.env.DELIVERY_TOKEN as string,
165-
environment: process.env.ENVIRONMENT as string,
166-
live_preview: {
167-
enable: false,
168-
preview_token: previewToken
169-
}
170-
})
171-
stack.livePreviewQuery({
172-
contentTypeUid: 'blog_post',
173-
live_preview: 'ser',
174-
})
175-
const result = await stack.contentType('blog_post').entry(entryUid).fetch<TEntry>();
176-
expect(result).toBeDefined();
177-
expect(result._version).toBeDefined();
178-
expect(result.locale).toEqual('en-us');
179-
expect(result.uid).toBeDefined();
180-
expect(result.created_by).toBeDefined();
181-
expect(result.updated_by).toBeDefined();
167+
it("should check for entry is when live preview is disabled with preview token", async () => {
168+
const stack = contentstack.stack({
169+
host: process.env.HOST as string,
170+
apiKey: process.env.API_KEY as string,
171+
deliveryToken: process.env.DELIVERY_TOKEN as string,
172+
environment: process.env.ENVIRONMENT as string,
173+
live_preview: {
174+
enable: false,
175+
preview_token: previewToken,
176+
},
182177
});
183-
})
178+
stack.livePreviewQuery({
179+
contentTypeUid: "blog_post",
180+
live_preview: "ser",
181+
});
182+
const result = await stack
183+
.contentType("blog_post")
184+
.entry(entryUid)
185+
.fetch<TEntry>();
186+
expect(result).toBeDefined();
187+
expect(result._version).toBeDefined();
188+
expect(result.locale).toEqual("en-us");
189+
expect(result.uid).toBeDefined();
190+
expect(result.created_by).toBeDefined();
191+
expect(result.updated_by).toBeDefined();
192+
});
193+
});

0 commit comments

Comments
 (0)