MCPcopy Index your code
hub / github.com/coder/coder / TestUserQuietHours

Function TestUserQuietHours

enterprise/coderd/users_test.go:25–229  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23const TimeFormatHHMM = coderd.TimeFormatHHMM
24
25func TestUserQuietHours(t *testing.T) {
26 t.Parallel()
27
28 t.Run("DefaultToUTC", func(t *testing.T) {
29 t.Parallel()
30
31 adminClient, adminUser := coderdenttest.New(t, &coderdenttest.Options{
32 LicenseOptions: &coderdenttest.LicenseOptions{
33 Features: license.Features{
34 codersdk.FeatureAdvancedTemplateScheduling: 1,
35 },
36 },
37 })
38
39 client, user := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
40 ctx := testutil.Context(t, testutil.WaitLong)
41 res, err := client.UserQuietHoursSchedule(ctx, user.ID.String())
42 require.NoError(t, err)
43 require.Equal(t, "UTC", res.Timezone)
44 require.Equal(t, "00:00", res.Time)
45 require.Equal(t, "CRON_TZ=UTC 0 0 * * *", res.RawSchedule)
46 })
47
48 t.Run("OK", func(t *testing.T) {
49 t.Parallel()
50 // Using 10 for minutes lets us test a format bug in which values greater
51 // than 5 were causing the API to explode because the time was returned
52 // incorrectly
53 defaultQuietHoursSchedule := "CRON_TZ=America/Chicago 10 1 * * *"
54 defaultScheduleParsed, err := cron.Daily(defaultQuietHoursSchedule)
55 require.NoError(t, err)
56 nextTime := defaultScheduleParsed.Next(time.Now().In(defaultScheduleParsed.Location()))
57 if time.Until(nextTime) < time.Hour {
58 // Use a different default schedule instead, because we want to avoid
59 // the schedule "ticking over" during this test run.
60 defaultQuietHoursSchedule = "CRON_TZ=America/Chicago 10 13 * * *"
61 defaultScheduleParsed, err = cron.Daily(defaultQuietHoursSchedule)
62 require.NoError(t, err)
63 }
64
65 dv := coderdtest.DeploymentValues(t)
66 dv.UserQuietHoursSchedule.DefaultSchedule.Set(defaultQuietHoursSchedule)
67
68 adminClient, adminUser := coderdenttest.New(t, &coderdenttest.Options{
69 Options: &coderdtest.Options{
70 DeploymentValues: dv,
71 },
72 LicenseOptions: &coderdenttest.LicenseOptions{
73 Features: license.Features{
74 codersdk.FeatureAdvancedTemplateScheduling: 1,
75 },
76 },
77 })
78
79 // Do it with another user to make sure that we're not hitting RBAC
80 // errors.
81 client, user := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
82

Callers

nothing calls this directly

Calls 15

StatusCodeMethod · 0.95
NewFunction · 0.92
CreateAnotherUserFunction · 0.92
ContextFunction · 0.92
DailyFunction · 0.92
DeploymentValuesFunction · 0.92
NowFunction · 0.92
LocationMethod · 0.80
TimeParsedMethod · 0.80
RunMethod · 0.65
NextMethod · 0.65

Tested by

no test coverage detected