8000 feat: update workspace deadline when workspace ttl updated by johnstcn · Pull Request #2165 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: update workspace deadline when workspace ttl updated #2165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 9, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: WorkspaceScheduleForm: add unit tests
  • Loading branch information
johnstcn committed Jun 9, 2022
commit 9a7c623d8039b59da875a82de6099d7bb556924e
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Language, validationSchema, WorkspaceScheduleFormValues } from "./WorkspaceScheduleForm"
import dayjs from "dayjs"
import { Workspace } from "../../api/typesGenerated"
import * as Mocks from "../../testHelpers/entities"
import { Language, ttlShutdownAt, validationSchema, WorkspaceScheduleFormValues } from "./WorkspaceScheduleForm"
import { zones } from "./zones"

const valid: WorkspaceScheduleFormValues = {
Expand Down Expand Up @@ -155,3 +158,51 @@ describe("validationSchema", () => {
expect(validate).toThrowError("ttl must be less than or equal to 168")
})
})

describe("ttlShutdownAt", () => {
it.each<[dayjs.Dayjs, Workspace, string, number, string]>([
[
dayjs("2022-05-17T18:09:00Z"),
{
...Mocks.MockWorkspace,
latest_build: {
...Mocks.MockWorkspaceBuild,
transition: "stop",
},
},
"America/Chicago",
1,
"Your workspace will automatically shut down after this amount of time has elapsed.",
],
[
dayjs("2022-05-17T18:09:00Z"),
Mocks.MockWorkspace,
"America/Chicago",
0,
"Your workspace will not automatically shut down.",
],
[
dayjs("2022-05-17T18:09:00Z"),
Mocks.MockWorkspace,
"America/Chicago",
1,
"Your workspace will shut down at 01:39 PM CDT.",
],
[
dayjs("2022-05-17T18:10:00Z"),
Mocks.MockWorkspace,
"America/Chicago",
1,
"⚠️ Your workspace will shut down within 30 minutes. ⚠️",
],
[
dayjs("2022-05-17T18:40:00Z"),
Mocks.MockWorkspace,
"America/Chicago",
1,
"⚠️ Your workspace will shut down immediately! ⚠️",
],
])("ttlShutdownAt(%p, %p, %p, %p) returns %p", (now, workspace, timezone, ttlHours, expected) => {
expect(ttlShutdownAt(now, workspace, timezone, ttlHours)).toEqual(expected)
})
})
0