Skip to content
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
5 changes: 4 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ require('./entry/spread');
require('./asset/find');
require('./asset/find-result-wrapper');
require('./asset/spread');
require('./asset/image-transformation.js');
require('./asset/image-transformation.js');

// Live-preview
require('./live-preview/live-preview-test.js')
91 changes: 91 additions & 0 deletions test/live-preview/live-preview-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

'use strict';

const test = require('tape');
const Contentstack = require('../../dist/node/contentstack.js');

test('should check for values initialized', function(assert) {
const stack = Contentstack.Stack({
'api_key': process.env.API_KEY,
'delivery_token': process.env.DELIVERY_TOKEN,
'environment': process.env.ENVIRONMENT
});
const livePreviewObject = stack.config.live_preview;
assert.equal(livePreviewObject.enable, false);
assert.equal(stack.config.host, 'cdn.contentstack.io'); // rest-preview.contentstack.com
assert.end();
});

test('should check host when live preview is enabled and management token is provided', function(assert) {
const stack = Contentstack.Stack({
'api_key': process.env.API_KEY,
'delivery_token': process.env.DELIVERY_TOKEN,
'environment': process.env.ENVIRONMENT,
live_preview: {
enable: true,
management_token: 'management_token'
}
});
const livePreviewObject = stack.config.live_preview;
assert.notEqual(livePreviewObject, 'undefined');
assert.notEqual(livePreviewObject.enable, 'undefined');
assert.notEqual(livePreviewObject.host, 'undefined');
assert.equal(stack.config.host, 'cdn.contentstack.io'); // rest-preview.contentstack.com
assert.end();
});

test('should check host when live preview is disabled and management token is provided', function(assert) {
const stack = Contentstack.Stack({
'api_key': process.env.API_KEY,
'delivery_token': process.env.DELIVERY_TOKEN,
'environment': process.env.ENVIRONMENT,
live_preview: {
enable: false,
management_token: 'management_token'
}
});
const livePreviewObject = stack.config.live_preview;
assert.notEqual(livePreviewObject, 'undefined');
assert.equal(livePreviewObject.enable, false);
assert.notEqual(livePreviewObject.host, 'undefined');
assert.end();
});

test('should check host when live preview is enabled and preview token is provided', function(assert) {
const stack = Contentstack.Stack({
'api_key': process.env.API_KEY,
'delivery_token': process.env.DELIVERY_TOKEN,
'environment': process.env.ENVIRONMENT,
live_preview: {
enable: true,
preview_token: 'preview_token'
}
});
const livePreviewObject = stack.config.live_preview;
assert.notEqual(livePreviewObject, 'undefined');
assert.notEqual(livePreviewObject.enable, 'undefined');
assert.notEqual(livePreviewObject.host, 'undefined');
assert.notEqual(livePreviewObject.preview_token, 'undefined');
assert.equal(stack.config.host, 'cdn.contentstack.io');
assert.end();
});

test('should check host when live preview is disabled and preview token is provided', function(assert) {
const stack = Contentstack.Stack({
'api_key': process.env.API_KEY,
'delivery_token': process.env.DELIVERY_TOKEN,
'environment': process.env.ENVIRONMENT,
live_preview: {
enable: false,
preview_token: 'preview_token'
}
});
const livePreviewObject = stack.config.live_preview;
assert.notEqual(livePreviewObject, 'undefined');
assert.notEqual(livePreviewObject.enable, 'undefined');
assert.notEqual(livePreviewObject.host, 'undefined');
assert.notEqual(livePreviewObject.preview_token, 'undefined');
assert.equal(stack.config.host, 'cdn.contentstack.io');
assert.end();
});