Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Support Named Variables. Add appendVariable, getVariable, runSshScript, vibrate, waitToReturn actions. #8

Merged
merged 7 commits into from
Nov 21, 2018
Merged
21 changes: 21 additions & 0 deletions __tests__/actions/addToVariable.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { addToVariable } from '../../src/actions';

describe('addToVariable function', () => {

it('is a function', () => {
expect(typeof addToVariable).toBe('function');
});

it('builds a addToVariable action when a name is passed', () => {
const name = 'Test Variable';
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.appendvariable',
WFWorkflowActionParameters: {
WFVariableName: name,
},
};
const actual = addToVariable({ name });

expect(actual).toEqual(expected);
});
});
81 changes: 81 additions & 0 deletions __tests__/actions/getVariable.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { getVariable } from '../../src/actions';

import WFSerialization from '../../src/interfaces/WF/WFSerialization';

describe('getVariable function', () => {

it('is a function', () => {
expect(typeof getVariable).toBe('function');
});

it('builds a getVariable action when a variable name is passed', () => {
const name = 'variable';

const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.getvariable',
WFWorkflowActionParameters: {
WFVariable: {
Value: {
Type: 'Variable',
VariableName: name,
},
WFSerializationType: 'WFTextTokenAttachment',
},
},
};

const actual = getVariable({ variable: name });

expect(actual).toEqual(expected);
});

it('builds a getVariable action when a variable UUID is passed', () => {
const uuid = 'b74c81a8-192a-463f-a0a6-2d327963714f';

const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.getvariable',
WFWorkflowActionParameters: {
WFVariable: {
Value: {
OutputUUID: uuid,
Type: 'ActionOutput',
},
WFSerializationType: 'WFTextTokenAttachment',
},
},
};

const actual = getVariable({ variable: uuid });

expect(actual).toEqual(expected);
});

it('builds a getVariable action when a variable object is passed', () => {
const uuid = 'b74c81a8-192a-463f-a0a6-2d327963714f';

const variableObject: WFSerialization = {
Value: {
OutputUUID: uuid,
Type: 'ActionOutput',
},
WFSerializationType: 'WFTextTokenAttachment',
};

const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.getvariable',
WFWorkflowActionParameters: {
WFVariable: {
Value: {
OutputUUID: uuid,
Type: 'ActionOutput',
},
WFSerializationType: 'WFTextTokenAttachment',
},
},
};

const actual = getVariable({ variable: variableObject });

expect(actual).toEqual(expected);
});
});
36 changes: 36 additions & 0 deletions __tests__/actions/runScriptOverSsh.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { runScriptOverSsh } from '../../src/actions';

describe('runScriptOverSsh function', () => {

it('is a function', () => {
expect(typeof runScriptOverSsh).toBe('function');
});

it('builds a runScriptOverSsh action when options are passed', () => {
const host = '192.168.1.1';
const password = 'root';
const port = '22';
const script = 'uptime';
const user = 'root';

const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.runsshscript',
WFWorkflowActionParameters: {
WFSSHHost: host,
WFSSHPassword: password,
WFSSHPort: port,
WFSSHScript: script,
WFSSHUser: user,
},
};
const actual = runScriptOverSsh({
host,
password,
port,
script,
user,
});

expect(actual).toEqual(expected);
});
});
19 changes: 19 additions & 0 deletions __tests__/actions/vibrateDevice.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { vibrateDevice } from '../../src/actions';

describe('vibrateDevice function', () => {

it('is a function', () => {
expect(typeof vibrateDevice).toBe('function');
});

it('builds a vibrateDevice action when no options are passed', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.vibrate',
WFWorkflowActionParameters: {},
};
const actual = vibrateDevice({});

expect(actual).toEqual(expected);
});

});
19 changes: 19 additions & 0 deletions __tests__/actions/waitToReturn.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { waitToReturn } from '../../src/actions';

describe('waitToReturn function', () => {

it('is a function', () => {
expect(typeof waitToReturn).toBe('function');
});

it('builds a waitToReturn action when no options are passed', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.waittoreturn',
WFWorkflowActionParameters: {},
};
const actual = waitToReturn({});

expect(actual).toEqual(expected);
});

});
12 changes: 12 additions & 0 deletions __tests__/utils/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
buildShortcut,
buildShortcutTemplate,
encodeShortcut,
testUUID,
withUUID,
withVariables,
} from '../../src/utils';
Expand All @@ -15,6 +16,9 @@ import {
import {
encodeShortcut as encodeShortcutDirect,
} from '../../src/utils/encodeShortcut';
import {
testUUID as testUUIDDirect,
} from '../../src/utils/testUUID';
import {
withUUID as withUUIDDirect,
} from '../../src/utils/withUUID';
Expand Down Expand Up @@ -48,6 +52,14 @@ describe('util index.ts file', () => {
expect(actual).toEqual(expected);
});

it('exports testUUID as a named function', () => {

const actual = testUUID.toString();
const expected = testUUIDDirect.toString();

expect(actual).toEqual(expected);
});

it('exports withUUID as a named function', () => {

const actual = withUUID.toString();
Expand Down
18 changes: 18 additions & 0 deletions __tests__/utils/testUUID.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { testUUID } from '../../src/utils';

describe('testUUID function', () => {

it('is a function', () => {
expect(typeof testUUID).toBe('function');
});

it('returns true for a valid UUID string', () => {
const actual = testUUID('b74c81a8-192a-463f-a0a6-2d327963714f');
expect(actual).toBe(true);
});

it('returns true for a invalid UUID string', () => {
const actual = testUUID('');
expect(actual).toBe(false);
});
});
109 changes: 105 additions & 4 deletions __tests__/utils/withVariables.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { withVariables } from '../../src/utils';
import WFSerialization from '../../src/interfaces/WF/WFSerialization';

describe('withVariables function', () => {

it('is a function', () => {
expect(typeof withVariables).toBe('function');
});
Expand All @@ -21,7 +20,7 @@ describe('withVariables function', () => {
expect(actual).toEqual(expected);
});

it('returns an attachment object when passed a single variable', () => {
it('returns an attachment object when passed a single magic variable', () => {
const uuid = 'b74c81a8-192a-463f-a0a6-2d327963714f';

const actual = withVariables`${uuid}`;
Expand All @@ -41,7 +40,7 @@ describe('withVariables function', () => {
expect(actual).toEqual(expected);
});

it('returns an attachment object when passed a variable in the middle of a string', () => {
it('returns an attachment object when passed a magic variable in the middle of a string', () => {
const uuid = 'b74c81a8-192a-463f-a0a6-2d327963714f';

const actual = withVariables`Hello, ${uuid} world!`;
Expand All @@ -61,7 +60,47 @@ describe('withVariables function', () => {
expect(actual).toEqual(expected);
});

it('returns an attachment object when passed multiple variables in a string', () => {
it('returns an attachment object when passed a single named variable', () => {
const name = 'Test Variable';

const actual = withVariables`${name}`;
const expected: WFSerialization = {
WFSerializationType: 'WFTextTokenString',
Value: {
string: '', // Object replacement character
attachmentsByRange: {
'{0, 1}': {
Type: 'Variable',
VariableName: 'Test Variable',
},
},
},
};

expect(actual).toEqual(expected);
});

it('returns an attachment object when passed a named variable in the middle of a string', () => {
const name = 'Test Variable';

const actual = withVariables`Hello, ${name} world!`;
const expected: WFSerialization = {
WFSerializationType: 'WFTextTokenString',
Value: {
string: 'Hello,  world!', // Contains object replacement character
attachmentsByRange: {
'{7, 1}': {
Type: 'Variable',
VariableName: 'Test Variable',
},
},
},
};

expect(actual).toEqual(expected);
});

it('returns an attachment object when passed multiple magic variables in a string', () => {
const uuid1 = 'b74c81a8-192a-463f-a0a6-2d327963714f';
const uuid2 = '4e8b6858-cf85-4ffe-9019-efb421248510';
const uuid3 = 'af9c2e97-8af2-4029-8664-18fb158dbd16';
Expand Down Expand Up @@ -96,4 +135,66 @@ describe('withVariables function', () => {
expect(actual).toEqual(expected);
});

it('returns an attachment object when passed multiple named variables in a string', () => {
const name1 = 'Test Variable1';
const name2 = 'Test Variable2';
const name3 = 'Test Variable3';
const name4 = 'Test Variable4';

const actual = withVariables`${name1} Going ${name2}${name3} to the ${name4} blacksmith`;
const expected: WFSerialization = {
WFSerializationType: 'WFTextTokenString',
Value: {
string: ' Going  to the  blacksmith', // Contains object replacement character
attachmentsByRange: {
'{0, 1}': {
Type: 'Variable',
VariableName: 'Test Variable1',
},
'{8, 1}': {
Type: 'Variable',
VariableName: 'Test Variable2',
},
'{9, 1}': {
Type: 'Variable',
VariableName: 'Test Variable3',
},
'{18, 1}': {
Type: 'Variable',
VariableName: 'Test Variable4',
},
},
},
};

expect(actual).toEqual(expected);
});

it(
'returns an attachment object when passed a named variable and a magic variable in a string',
() => {
const uuid = 'b74c81a8-192a-463f-a0a6-2d327963714f';
const name = 'Test Variable';

const actual = withVariables`${uuid} Going ${name} to the blacksmith`;
const expected: WFSerialization = {
WFSerializationType: 'WFTextTokenString',
Value: {
string: ' Going  to the blacksmith', // Contains object replacement character
attachmentsByRange: {
'{0, 1}': {
OutputUUID: 'b74c81a8-192a-463f-a0a6-2d327963714f',
Type: 'ActionOutput',
},
'{8, 1}': {
Type: 'Variable',
VariableName: 'Test Variable',
},
},
},
};

expect(actual).toEqual(expected);
},
);
});
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(ts|js)x?$',
testPathIgnorePatterns: [
'/node_modules/',
'/shortcuts/',
'/__tests__/_fixtures/',
],
coverageDirectory: 'coverage',
Expand Down
Loading