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

Commit

Permalink
Merge pull request #24 from JB1905/master
Browse files Browse the repository at this point in the history
Add setWiFi & setCellularData actions
  • Loading branch information
joshfarrant committed Nov 30, 2018
2 parents 079aed0 + 1dbb212 commit 0cbab36
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 0 deletions.
34 changes: 34 additions & 0 deletions __tests__/actions/setCellularData.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { setCellularData } from '../../src/actions';

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

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

it('builds a setCellularData action when no value is passed', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.cellulardata.set',
WFWorkflowActionParameters: {
OnValue: true,
},
};
const actual = setCellularData({});

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

it('builds a setCellularData action with given value', () => {
const value = false;
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.cellulardata.set',
WFWorkflowActionParameters: {
OnValue: value,
},
};
const actual = setCellularData({ value });

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

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

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

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

it('builds a setWiFi action when no value is passed', () => {
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.wifi.set',
WFWorkflowActionParameters: {
OnValue: true,
},
};
const actual = setWiFi({});

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

it('builds a setWiFi action with given value', () => {
const value = false;
const expected = {
WFWorkflowActionIdentifier: 'is.workflow.actions.wifi.set',
WFWorkflowActionParameters: {
OnValue: value,
},
};
const actual = setWiFi({ value });

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

});
4 changes: 4 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import runShortcut from './runShortcut';
import setAirplaneMode from './setAirplaneMode';
import setBluetooth from './setBluetooth';
import setBrightness from './setBrightness';
import setCellularData from './setCellularData';
import setLowPowerMode from './setLowPowerMode';
import setName from './setName';
import setTorch from './setTorch';
import setVariable from './setVariable';
import setWiFi from './setWiFi';
import showResult from './showResult';
import text from './text';
import url from './url';
Expand Down Expand Up @@ -55,10 +57,12 @@ export {
setAirplaneMode,
setBluetooth,
setBrightness,
setCellularData,
setLowPowerMode,
setName,
setTorch,
setVariable,
setWiFi,
showResult,
text,
url,
Expand Down
30 changes: 30 additions & 0 deletions src/actions/setCellularData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction';

/**
* Set setCellularData Action. Sets the device's cellular data to on or off.
*
* ```js
* setCellularData({
* value: true,
* });
* ```
*/
const setCellularData = (
options: {
/** Enable or disable cellular data */
value?: boolean,
},
): WFWorkflowAction => {
const {
value = true,
} = options;

return {
WFWorkflowActionIdentifier: 'is.workflow.actions.cellulardata.set',
WFWorkflowActionParameters: {
OnValue: value,
},
};
};

export default setCellularData;
30 changes: 30 additions & 0 deletions src/actions/setWiFi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction';

/**
* Set setWiFi Action. Sets the device's WiFi to on or off.
*
* ```js
* setWiFi({
* value: true,
* });
* ```
*/
const setWiFi = (
options: {
/** Enable or disable WiFi */
value?: boolean,
},
): WFWorkflowAction => {
const {
value = true,
} = options;

return {
WFWorkflowActionIdentifier: 'is.workflow.actions.wifi.set',
WFWorkflowActionParameters: {
OnValue: value,
},
};
};

export default setWiFi;
2 changes: 2 additions & 0 deletions src/interfaces/WF/WFWorkflowActionIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ type WFWorkflowActionIdentifier = (
| 'is.workflow.actions.airplanemode.set'
| 'is.workflow.actions.ask'
| 'is.workflow.actions.bluetooth.set'
| 'is.workflow.actions.cellulardata.set'
| 'is.workflow.actions.choosefrommenu'
| 'is.workflow.actions.comment'
| 'is.workflow.actions.conditional'
Expand Down Expand Up @@ -32,6 +33,7 @@ type WFWorkflowActionIdentifier = (
| 'is.workflow.actions.vibrate'
| 'is.workflow.actions.viewresult'
| 'is.workflow.actions.waittoreturn'
| 'is.workflow.actions.wifi.set'
);

export default WFWorkflowActionIdentifier;

0 comments on commit 0cbab36

Please sign in to comment.