Skip to content

Commit

Permalink
Merge 5476ed0 into 4af9986
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya committed Dec 3, 2018
2 parents 4af9986 + 5476ed0 commit 63bb273
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 0 deletions.
77 changes: 77 additions & 0 deletions __tests__/actions/generateHash.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { generateHash } from '../../src/actions';

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

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

it('builds a generateHash action', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.hash',
WFWorkflowActionParameters: {
WFHashType: 'MD5',
},
};
const actual = generateHash({});

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

it('builds a generateHash action (MD5)', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.hash',
WFWorkflowActionParameters: {
WFHashType: 'MD5',
},
};
const actual = generateHash({
type: 'MD5',
});

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

it('builds a generateHash action (SHA1)', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.hash',
WFWorkflowActionParameters: {
WFHashType: 'SHA1',
},
};
const actual = generateHash({
type: 'SHA1',
});

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

it('builds a generateHash action (SHA256)', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.hash',
WFWorkflowActionParameters: {
WFHashType: 'SHA256',
},
};
const actual = generateHash({
type: 'SHA256',
});

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

it('builds a generateHash action (SHA512)', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.hash',
WFWorkflowActionParameters: {
WFHashType: 'SHA512',
},
};
const actual = generateHash({
type: 'SHA512',
});

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

});
34 changes: 34 additions & 0 deletions src/actions/generateHash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { withActionOutput } from '../utils';

import WFHashType from '../interfaces/WF/WFHashType';
import WFSerialization from '../interfaces/WF/WFSerialization';
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction';

/**
* Generate Hash Action. Generates a MD5/SHA1 hash from the input.
*
* ```js
* generateHash({
* type: 'MD5'
* });
* ```
*/
const generateHash = (
options: {
/** The type of hash to use */
type?: WFSerialization | WFHashType,
},
): WFWorkflowAction => {
const {
type = 'MD5',
} = options;

return {
WFWorkflowActionIdentifier: 'is.workflow.actions.hash',
WFWorkflowActionParameters: {
WFHashType: type,
},
};
};

export default withActionOutput(generateHash);
2 changes: 2 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import conditional from './conditional';
import continueShortcutInApp from './continueShortcutInApp';
import count from './count';
import exitShortcut from './exitShortcut';
import generateHash from './generateHash';
import getBatteryLevel from './getBatteryLevel';
import getContentsOfUrl from './getContentsOfUrl';
import getCurrentIpAddress from './getCurrentIpAddress';
Expand Down Expand Up @@ -48,6 +49,7 @@ export {
continueShortcutInApp,
count,
exitShortcut,
generateHash,
getBatteryLevel,
getContentsOfUrl,
getCurrentIpAddress,
Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/WF/WFHashType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type WFHashType = (
'MD5'
| 'SHA1'
| 'SHA256'
| 'SHA512'
);

export default WFHashType;
1 change: 1 addition & 0 deletions src/interfaces/WF/WFWorkflowActionIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type WFWorkflowActionIdentifier = (
| 'is.workflow.actions.getvalueforkey'
| 'is.workflow.actions.getvariable'
| 'is.workflow.actions.handoff'
| 'is.workflow.actions.hash'
| 'is.workflow.actions.lowpowermode.set'
| 'is.workflow.actions.math'
| 'is.workflow.actions.nothing'
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/WF/WFWorkflowActionParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import WFCondition from './WFCondition';
import WFCountType from './WFCountType';
import WFFlashlightSetting from './WFFlashlightSetting';
import WFGetDictionaryValueType from './WFGetDictionaryValueType';
import WFHashType from './WFHashType';
import WFHTTPBodyType from './WFHTTPBodyType';
import WFHTTPMethod from './WFHTTPMethod';
import WFInputType from './WFInputType';
Expand Down Expand Up @@ -34,6 +35,7 @@ interface WFWorkflowActionParameters {
WFFlashlightSetting?: WFFlashlightSetting;
WFFormValues?: WFSerialization;
WFGetDictionaryValueType?: WFGetDictionaryValueType;
WFHashType?: WFSerialization | WFHashType;
WFHTTPBodyType?: WFHTTPBodyType;
WFHTTPHeaders?: WFSerialization;
WFHTTPMethod?: WFHTTPMethod;
Expand Down

0 comments on commit 63bb273

Please sign in to comment.