|
| 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 | +}); |
0 commit comments