-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
249 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,182 @@ | ||
import { getTimeBetweenDates } from '../../src/actions'; | ||
import { askWhenRun } from '../../src/variables'; | ||
|
||
import WFSerialization from '../../src/interfaces/WF/WFSerialization'; | ||
|
||
describe('getTimeBetweenDates function', () => { | ||
|
||
it('is a function', () => { | ||
expect(typeof getTimeBetweenDates).toBe('function'); | ||
}); | ||
|
||
it('builds a getTimeBetweenDates action', () => { | ||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.gettimebetweendates', | ||
WFWorkflowActionParameters: {}, | ||
}; | ||
const actual = getTimeBetweenDates({}); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a getTimeBetweenDates action with a specified time unit', () => { | ||
const unit = 'Hours'; | ||
|
||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.gettimebetweendates', | ||
WFWorkflowActionParameters: { | ||
WFTimeUntilUnit: unit, | ||
}, | ||
}; | ||
|
||
const actual = getTimeBetweenDates({ unit }); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a getTimeBetweenDates action that asks for time unit when run', () => { | ||
const unit = askWhenRun; | ||
|
||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.gettimebetweendates', | ||
WFWorkflowActionParameters: { | ||
WFTimeUntilUnit: unit, | ||
}, | ||
}; | ||
|
||
const actual = getTimeBetweenDates({ unit }); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a getTimeBetweenDates action that has a custom start time', () => { | ||
const date = '3/5/2011 5:42PM'; | ||
|
||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.gettimebetweendates', | ||
WFWorkflowActionParameters: { | ||
WFTimeUntilReferenceDate: 'Other', | ||
WFTimeUntilCustomDate: date, | ||
}, | ||
}; | ||
|
||
const actual = getTimeBetweenDates({ date }); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a getTimeBetweenDates action that has a garbage custom start time', () => { | ||
const date = 'thisIsGarbageButItIsStillValid'; | ||
|
||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.gettimebetweendates', | ||
WFWorkflowActionParameters: { | ||
WFTimeUntilReferenceDate: 'Other', | ||
WFTimeUntilCustomDate: date, | ||
}, | ||
}; | ||
|
||
const actual = getTimeBetweenDates({ date }); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a getTimeBetweenDates action that has a custom start time and unit', () => { | ||
const unit = 'Hours'; | ||
const date = '3/5/2011 5:42PM'; | ||
|
||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.gettimebetweendates', | ||
WFWorkflowActionParameters: { | ||
WFTimeUntilUnit: unit, | ||
WFTimeUntilReferenceDate: 'Other', | ||
WFTimeUntilCustomDate: date, | ||
}, | ||
}; | ||
|
||
const actual = getTimeBetweenDates({ unit, date }); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a getTimeBetweenDates action that asks for a custom time when run', () => { | ||
const customDateAsk: WFSerialization = { | ||
Value: { | ||
string: '', // Object replacement character | ||
attachmentsByRange: { | ||
'{0, 1}': { | ||
Type: 'Ask', | ||
}, | ||
}, | ||
}, | ||
WFSerializationType: 'WFTextTokenString', | ||
}; | ||
|
||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.gettimebetweendates', | ||
WFWorkflowActionParameters: { | ||
WFTimeUntilReferenceDate: 'Other', | ||
WFTimeUntilCustomDate: customDateAsk, | ||
}, | ||
}; | ||
|
||
const actual = getTimeBetweenDates({ date: customDateAsk }); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a getTimeBetweenDates action that uses a variable for a custom time', () => { | ||
const variableObject: WFSerialization = { | ||
Value: { | ||
string: '', // Object replacement character | ||
attachmentsByRange: { | ||
'{0, 1}': { | ||
OutputUUID: 'b74c81a8-192a-463f-a0a6-2d327963714f', | ||
Type: 'ActionOutput', | ||
}, | ||
}, | ||
}, | ||
WFSerializationType: 'WFTextTokenString', | ||
}; | ||
|
||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.gettimebetweendates', | ||
WFWorkflowActionParameters: { | ||
WFTimeUntilReferenceDate: 'Other', | ||
WFTimeUntilCustomDate: variableObject, | ||
}, | ||
}; | ||
|
||
const actual = getTimeBetweenDates({ date: variableObject }); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('builds a getTimeBetweenDates action that asks for a unit and custom time when run', () => { | ||
const unit = askWhenRun; | ||
const customDateAsk: WFSerialization = { | ||
Value: { | ||
string: '', // Object replacement character | ||
attachmentsByRange: { | ||
'{0, 1}': { | ||
Type: 'Ask', | ||
}, | ||
}, | ||
}, | ||
WFSerializationType: 'WFTextTokenString', | ||
}; | ||
|
||
const expected = { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.gettimebetweendates', | ||
WFWorkflowActionParameters: { | ||
WFTimeUntilUnit: unit, | ||
WFTimeUntilReferenceDate: 'Other', | ||
WFTimeUntilCustomDate: customDateAsk, | ||
}, | ||
}; | ||
|
||
const actual = getTimeBetweenDates({ unit, date: customDateAsk }); | ||
|
||
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,41 @@ | ||
import { withActionOutput } from '../utils'; | ||
|
||
import WFSerialization from '../interfaces/WF/WFSerialization'; | ||
import WFTimeUntilUnit from '../interfaces/WF/WFTimeUntilUnit'; | ||
import WFWorkflowAction from '../interfaces/WF/WFWorkflowAction'; | ||
|
||
/** | ||
* Get Time Between Dates Action. Subtracts the specified date from the date passed | ||
* into the action. For example, this action could get the number of minutes from | ||
* now until a calendar event passed in as input. | ||
* | ||
* ```js | ||
* getTimeBetweenDates({ | ||
* unit: 'Days', | ||
* date: '3/5/2011 5:45pm', | ||
* }); | ||
* ``` | ||
*/ | ||
const getTimeBetweenDates = ( | ||
options: { | ||
/** The unit of time for the result. Defaults to 'Minutes' */ | ||
unit?: WFSerialization | WFTimeUntilUnit, | ||
/** The date/time to calculate the difference from. Defaults to empty string */ | ||
date?: WFSerialization | string, | ||
}, | ||
): WFWorkflowAction => { | ||
const { | ||
unit = 'Minutes', | ||
date = '', | ||
} = options; | ||
|
||
return { | ||
WFWorkflowActionIdentifier: 'is.workflow.actions.gettimebetweendates', | ||
WFWorkflowActionParameters: { | ||
...(unit !== 'Minutes' && { WFTimeUntilUnit: unit }), | ||
...(date !== '' && { WFTimeUntilReferenceDate: 'Other', WFTimeUntilCustomDate: date }), | ||
}, | ||
}; | ||
}; | ||
|
||
export default withActionOutput(getTimeBetweenDates); |
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 WFTimeUntilReferenceDate = ( | ||
'Right Now' | ||
| 'Other' | ||
); | ||
|
||
export default WFTimeUntilReferenceDate; |
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,12 @@ | ||
type WFTimeUntilUnit = ( | ||
'Total Time' | ||
| 'Seconds' | ||
| 'Minutes' | ||
| 'Hours' | ||
| 'Days' | ||
| 'Weeks' | ||
| 'Months' | ||
| 'Years' | ||
); | ||
|
||
export default WFTimeUntilUnit; |
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