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
55dotenv . 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 . status ) . toEqual ( 403 ) ;
136+ }
137+ } ) ;
135138
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 ( ) ;
139+ it ( "should check for entry is when live preview is disabled with management token" , async ( ) => {
140+ const stack = contentstack . stack ( {
141+ host : process . env . HOST as string ,
142+ apiKey : process . env . API_KEY as string ,
143+ deliveryToken : process . env . DELIVERY_TOKEN as string ,
144+ environment : process . env . ENVIRONMENT as string ,
145+ live_preview : {
146+ enable : false ,
147+ management_token : managementToken ,
148+ } ,
149+ } ) ;
150+ stack . livePreviewQuery ( {
151+ contentTypeUid : "blog_post" ,
152+ live_preview : "ser" ,
158153 } ) ;
154+ const result = await stack
155+ . contentType ( "blog_post" )
156+ . entry ( entryUid )
157+ . fetch < TEntry > ( ) ;
158+ expect ( result ) . toBeDefined ( ) ;
159+ expect ( result . _version ) . toBeDefined ( ) ;
160+ expect ( result . locale ) . toEqual ( "en-us" ) ;
161+ expect ( result . uid ) . toBeDefined ( ) ;
162+ expect ( result . created_by ) . toBeDefined ( ) ;
163+ expect ( result . updated_by ) . toBeDefined ( ) ;
164+ } ) ;
159165
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 ( ) ;
166+ it ( "should check for entry is when live preview is disabled with preview token" , async ( ) => {
167+ const stack = contentstack . stack ( {
168+ host : process . env . HOST as string ,
169+ apiKey : process . env . API_KEY as string ,
170+ deliveryToken : process . env . DELIVERY_TOKEN as string ,
171+ environment : process . env . ENVIRONMENT as string ,
172+ live_preview : {
173+ enable : false ,
174+ preview_token : previewToken ,
175+ } ,
182176 } ) ;
183- } )
177+ stack . livePreviewQuery ( {
178+ contentTypeUid : "blog_post" ,
179+ live_preview : "ser" ,
180+ } ) ;
181+ const result = await stack
182+ . contentType ( "blog_post" )
183+ . entry ( entryUid )
184+ . fetch < TEntry > ( ) ;
185+ expect ( result ) . toBeDefined ( ) ;
186+ expect ( result . _version ) . toBeDefined ( ) ;
187+ expect ( result . locale ) . toEqual ( "en-us" ) ;
188+ expect ( result . uid ) . toBeDefined ( ) ;
189+ expect ( result . created_by ) . toBeDefined ( ) ;
190+ expect ( result . updated_by ) . toBeDefined ( ) ;
191+ } ) ;
192+ } ) ;
0 commit comments