Skip to content

Commit 0c00db3

Browse files
committed
Modify New-ScheduledCommand so that it always includes StartAfter
1 parent f19539c commit 0c00db3

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

PoshBot/Plugins/Builtin/Public/New-ScheduledCommand.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ function New-ScheduledCommand {
8181
if ($PSBoundParameters.ContainsKey('StartAfter')) {
8282
$schedMsg = [ScheduledMessage]::new($Interval, $value, $botMsg, [datetime]$StartAfter)
8383
} else {
84-
$schedMsg = [ScheduledMessage]::new($Interval, $value, $botMsg)
84+
$StartAfter = Get-Date
85+
$schedMsg = [ScheduledMessage]::new($Interval, $value, $botMsg, [datetime]$StartAfter)
8586
}
8687
} elseIf ($PSCmdlet.ParameterSetName -eq 'once') {
8788
# This command will be executed once then removed from the scheduler
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
InModuleScope PoshBot {
2+
3+
Describe ScheduledMessage {
4+
# Mock a message
5+
$msg = [Message]::new()
6+
$msg.Id = 1
7+
$msg.Text = "This is a test message"
8+
9+
# Call constructor
10+
$Interval = 'Days'
11+
$TimeValue = 1
12+
$Message = $msg
13+
$StartAfter = (Get-Date).AddMinutes(1)
14+
15+
Context "Constructor: String, Int, Message, DateTime" {
16+
17+
$ScheduledMessage = [ScheduledMessage]::new($Interval, $TimeValue, $Message, $StartAfter)
18+
19+
It 'TimeInterval should match argument' {
20+
$ScheduledMessage.TimeInterval | Should be $Interval
21+
}
22+
23+
It 'TimeValue should match argument' {
24+
$ScheduledMessage.TimeValue | Should be $TimeValue
25+
}
26+
27+
It 'Message Id should be 1' {
28+
$ScheduledMessage.Message.Id | Should be 1
29+
}
30+
It 'Message Text should match argument' {
31+
$ScheduledMessage.Message.Text | Should match $msg.Text
32+
}
33+
34+
It 'StartAfter value should match argument converted to UTC' {
35+
$ScheduledMessage.StartAfter | Should be $StartAfter.ToUniversalTime()
36+
}
37+
}
38+
39+
Context "Methods" {
40+
41+
}
42+
43+
}
44+
45+
}

0 commit comments

Comments
 (0)