Add and update unit tests for new create cloud variable functionality.

This commit is contained in:
Karishma Chadha 2018-11-14 15:46:51 -05:00
parent 3fc1b89b30
commit fad4d381bb
2 changed files with 119 additions and 6 deletions

View file

@ -4,6 +4,7 @@ const Variable = require('../../src/engine/variable');
const adapter = require('../../src/engine/adapter');
const Runtime = require('../../src/engine/runtime');
const events = require('../fixtures/events.json');
const Cloud = require('../../src/io/cloud');
test('spec', t => {
const target = new Target();
@ -71,6 +72,58 @@ test('createListVariable creates a list', t => {
t.end();
});
test('createVariable calls cloud io device\'s requestCreateCloudVariable', t => {
const runtime = new Runtime();
// Mock the requestCreateCloudVariable function
let requestCreateCloudWasCalled = false;
runtime.ioDevices.cloud.requestCreateCloudVariable = () => {
requestCreateCloudWasCalled = true;
};
const target = new Target(runtime);
target.isStage = true;
target.createVariable('foo', 'bar', Variable.SCALAR_TYPE, true /* isCloud */);
const variables = target.variables;
t.equal(Object.keys(variables).length, 1);
const variable = variables[Object.keys(variables)[0]];
t.equal(variable.id, 'foo');
t.equal(variable.name, 'bar');
t.equal(variable.type, Variable.SCALAR_TYPE);
t.equal(variable.value, 0);
// isCloud flag doesn't get set by the target createVariable function
t.equal(variable.isCloud, false);
t.equal(requestCreateCloudWasCalled, true);
t.end();
});
test('createVariable does not call cloud io device\'s requestCreateCloudVariable if target is not stage', t => {
const runtime = new Runtime();
// Mock the requestCreateCloudVariable function
let requestCreateCloudWasCalled = false;
runtime.ioDevices.cloud.requestCreateCloudVariable = () => {
requestCreateCloudWasCalled = true;
};
const target = new Target(runtime);
target.isStage = false;
target.createVariable('foo', 'bar', Variable.SCALAR_TYPE, true /* isCloud */);
const variables = target.variables;
t.equal(Object.keys(variables).length, 1);
const variable = variables[Object.keys(variables)[0]];
t.equal(variable.id, 'foo');
t.equal(variable.name, 'bar');
t.equal(variable.type, Variable.SCALAR_TYPE);
t.equal(variable.value, 0);
// isCloud flag doesn't get set by the target createVariable function
t.equal(variable.isCloud, false);
t.equal(requestCreateCloudWasCalled, false);
t.end();
});
test('createVariable throws when given invalid type', t => {
const target = new Target();
t.throws(