This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from bachya/current-ip-address
Add getCurrentIpAddress action
- Loading branch information
Showing
7 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { getCurrentIpAddress } from '../../src/actions'; | ||
|
||
describe('getCurrentIpAddress function', () => { | ||
|
||
it('is a function', () => { | ||
expect(typeof getCurrentIpAddress).toBe('function'); | ||
}); | ||
|
||
it('builds a getCurrentIpAddress action', () => { | ||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.getipaddress', | ||
WFWorkflowActionParameters: { | ||
WFIPAddressSourceOption: 'External', | ||
WFIPAddressTypeOption: 'IPv4', | ||
}, | ||
}; | ||
const actual = getCurrentIpAddress({}); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a getCurrentIpAddress action when an address is passed', () => { | ||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.getipaddress', | ||
WFWorkflowActionParameters: { | ||
WFIPAddressSourceOption: 'Local', | ||
WFIPAddressTypeOption: 'IPv4', | ||
}, | ||
}; | ||
const actual = getCurrentIpAddress({ address: 'Local' }); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a getCurrentIpAddress action when a type is passed', () => { | ||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.getipaddress', | ||
WFWorkflowActionParameters: { | ||
WFIPAddressSourceOption: 'External', | ||
WFIPAddressTypeOption: 'IPv6', | ||
}, | ||
}; | ||
const actual = getCurrentIpAddress({ type: 'IPv6' }); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { withActionOutput } from '../utils'; | ||
|
||
import WFIPAddressSourceOption from '../interfaces/WF/WFIPAddressSourceOption'; | ||
import WFIPAddressTypeOption from '../interfaces/WF/WFIPAddressTypeOption'; | ||
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction'; | ||
|
||
/** | ||
* Get Current IP Address Action. Returns the public/private IPv4 or IPv6 | ||
* address of the device. | ||
* | ||
* ```js | ||
* getCurrentIpAddress({ | ||
* 'address': 'External', | ||
* 'type': 'IPv4', | ||
* }); | ||
* ``` | ||
*/ | ||
const getCurrentIpAddress = ( | ||
options: { | ||
/** The address (public or private) to get */ | ||
address?: WFIPAddressSourceOption, | ||
/** The type of address to get */ | ||
type?: WFIPAddressTypeOption, | ||
}, | ||
): WFWorkflowAction => { | ||
const { | ||
address = 'External', | ||
type = 'IPv4', | ||
} = options; | ||
|
||
return { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.getipaddress', | ||
WFWorkflowActionParameters: { | ||
WFIPAddressSourceOption: address, | ||
WFIPAddressTypeOption: type, | ||
}, | ||
}; | ||
}; | ||
|
||
export default withActionOutput(getCurrentIpAddress); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type WFIPAddressSourceOption = ( | ||
'External' | ||
| 'Local' | ||
); | ||
|
||
export default WFIPAddressSourceOption; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type WFIPAddressTypeOption = ( | ||
'IPv4' | ||
| 'IPv6' | ||
); | ||
|
||
export default WFIPAddressTypeOption; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters