Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions automations_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ type AutomationRuleUpdateRequest struct {
Enabled *bool `json:"enabled,omitempty" toon:"enabled,omitempty"`
// Run cadence. Supports 4 fields (`hour day month weekday`, minute defaults to 0) and 5 fields (`minute hour day month weekday`).
CronExpr *string `json:"cron_expr,omitempty" toon:"cron_expr,omitempty"`
// IANA timezone `cron_expr` is evaluated in. The server must be able to load
// the name; an invalid value is rejected. Nil leaves the stored timezone
// unchanged, including a legacy empty string. An explicit empty string is
// stored as UTC, not reset to the account default.
Timezone *string `json:"timezone,omitempty" toon:"timezone,omitempty"`
// Whether the schedule trigger is enabled.
ScheduleTriggerEnabled *bool `json:"schedule_trigger_enabled,omitempty" toon:"schedule_trigger_enabled,omitempty"`
// New task prompt.
Expand Down
39 changes: 39 additions & 0 deletions automations_models_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package flashduty

import (
"encoding/json"
"strings"
"testing"
)

func TestAutomationRuleUpdateRequestTimezone(t *testing.T) {
omitted, err := json.Marshal(&AutomationRuleUpdateRequest{RuleID: "arule_1"})
if err != nil {
t.Fatal(err)
}
if strings.Contains(string(omitted), "timezone") {
t.Fatalf("nil timezone must be omitted, got %s", omitted)
}

empty, err := json.Marshal(&AutomationRuleUpdateRequest{
RuleID: "arule_1",
Timezone: String(""),
})
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(empty), `"timezone":""`) {
t.Fatalf("empty timezone must be sent, got %s", empty)
}

named, err := json.Marshal(&AutomationRuleUpdateRequest{
RuleID: "arule_1",
Timezone: String("Asia/Shanghai"),
})
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(named), `"timezone":"Asia/Shanghai"`) {
t.Fatalf("named timezone must be sent, got %s", named)
}
}
Loading