Skip to content

Commit

Permalink
test: added live preview test
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithad0703 committed Apr 12, 2024
1 parent e3e5b9d commit 3ca39b2
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
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();
});

0 comments on commit 3ca39b2

Please sign in to comment.