Skip to content

feat: add inactivity cleanup and failure cleanup configuration fields to Template Schedule Form #7402

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 24 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
744e476
added workspace actions entitlement
Kira-Pilot May 1, 2023
e6e1ec6
added workspace actions experiment
Kira-Pilot May 1, 2023
c049e9e
added new route for template enterprise meta
Kira-Pilot May 3, 2023
537ced7
removing new route; repurposing old
Kira-Pilot May 3, 2023
cd6a485
add new fields to get endpoints
Kira-Pilot May 3, 2023
6c984fa
Merge remote-tracking branch 'origin/main' into workspace-actions-tem…
Kira-Pilot May 3, 2023
57a9de7
removed workspace actions experiment
Kira-Pilot May 3, 2023
07cb07c
added logic to enterprise template store
Kira-Pilot May 3, 2023
7091fc1
added new form fields
Kira-Pilot May 3, 2023
e565225
feature flagged new fields
Kira-Pilot May 3, 2023
3d9f6f5
fix validation
Kira-Pilot May 4, 2023
abab4c8
fixed submit btn
Kira-Pilot May 4, 2023
ad37203
Merge remote-tracking branch 'origin/main' into workspace-actions-tem…
Kira-Pilot May 4, 2023
240f297
fix tests
Kira-Pilot May 4, 2023
be512ee
changed ttl defaults
Kira-Pilot May 4, 2023
8536b75
added FE tests
Kira-Pilot May 4, 2023
a05eb6c
added BE tests
Kira-Pilot May 4, 2023
0478e07
fixed lint
Kira-Pilot May 4, 2023
bba4722
adjusted comment language
Kira-Pilot May 4, 2023
c76a0f4
fixing unstaged changes check
Kira-Pilot May 4, 2023
9db6b13
fix test
Kira-Pilot May 4, 2023
a2a38f0
Merge branch 'main' into workspace-actions-template-route/kira-pilot
Kira-Pilot May 4, 2023
9fa9c5b
Update coderd/database/migrations/000122_add_template_cleanup_ttls.do…
Kira-Pilot May 5, 2023
43a2267
Update coderd/database/migrations/000122_add_template_cleanup_ttls.up…
Kira-Pilot May 5, 2023
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
added FE tests
  • Loading branch information
Kira-Pilot committed May 4, 2023
commit 8536b75b806d8f7d05c6f58002160aa6bbcc1b75
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
label="Time until cleanup (days)"
variant="outlined"
type="number"
aria-label="Failure Cleanup"
/>
</FormFields>
</FormSection>
Expand Down Expand Up @@ -388,6 +389,7 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
label="Time until cleanup (days)"
variant="outlined"
type="number"
aria-label="Inactivity Cleanup"
/>
</FormFields>
</FormSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { Language as FooterFormLanguage } from "components/FormFooter/FormFooter
import {
MockEntitlementsWithScheduling,
MockTemplate,
} from "../../../testHelpers/entities"
} from "testHelpers/entities"
import {
renderWithTemplateSettingsLayout,
waitForLoaderToBeRemoved,
} from "../../../testHelpers/renderHelpers"
} from "testHelpers/renderHelpers"
import { getValidationSchema } from "./TemplateScheduleForm"
import TemplateSchedulePage from "./TemplateSchedulePage"
import i18next from "i18next"
Expand All @@ -20,6 +20,8 @@ const { t } = i18next
const validFormValues = {
default_ttl_ms: 1,
max_ttl_ms: 2,
failure_ttl_ms: 7,
inactivity_ttl_ms: 180,
}

const renderTemplateSchedulePage = async () => {
Expand All @@ -33,9 +35,13 @@ const renderTemplateSchedulePage = async () => {
const fillAndSubmitForm = async ({
default_ttl_ms,
max_ttl_ms,
failure_ttl_ms,
inactivity_ttl_ms,
}: {
default_ttl_ms: number
max_ttl_ms: number
failure_ttl_ms: number
inactivity_ttl_ms: number
}) => {
const user = userEvent.setup()
const defaultTtlLabel = t("defaultTtlLabel", { ns: "templateSettingsPage" })
Expand All @@ -48,6 +54,16 @@ const fillAndSubmitForm = async ({
await user.clear(maxTtlField)
await user.type(maxTtlField, max_ttl_ms.toString())

const failureTtlField = screen.getByRole("checkbox", {
name: /Failure Cleanup/i,
})
await user.type(failureTtlField, failure_ttl_ms.toString())

const inactivityTtlField = screen.getByRole("checkbox", {
name: /Inactivity Cleanup/i,
})
await user.type(inactivityTtlField, inactivity_ttl_ms.toString())

const submitButton = await screen.findByText(
FooterFormLanguage.defaultSubmitLabel,
)
Expand All @@ -59,6 +75,9 @@ describe("TemplateSchedulePage", () => {
jest
.spyOn(API, "getEntitlements")
.mockResolvedValue(MockEntitlementsWithScheduling)

// remove when https://github.com/coder/coder/milestone/19 is completed.
jest.spyOn(API, "getExperiments").mockResolvedValue(["workspace_actions"])
})

it("succeeds", async () => {
Expand All @@ -71,7 +90,7 @@ describe("TemplateSchedulePage", () => {
await waitFor(() => expect(API.updateTemplateMeta).toBeCalledTimes(1))
})

test("ttl is converted to and from hours", async () => {
test("default and max ttl is converted to and from hours", async () => {
await renderTemplateSchedulePage()

jest.spyOn(API, "updateTemplateMeta").mockResolvedValueOnce({
Expand All @@ -92,7 +111,28 @@ describe("TemplateSchedulePage", () => {
)
})

it("allows a ttl of 7 days", () => {
test("failure and inactivity ttl converted to and from days", async () => {
await renderTemplateSchedulePage()

jest.spyOn(API, "updateTemplateMeta").mockResolvedValueOnce({
...MockTemplate,
...validFormValues,
})

await fillAndSubmitForm(validFormValues)
await waitFor(() => expect(API.updateTemplateMeta).toBeCalledTimes(1))
await waitFor(() =>
expect(API.updateTemplateMeta).toBeCalledWith(
"test-template",
expect.objectContaining({
failure_ttl_ms: validFormValues.failure_ttl_ms * 86400000,
inactivity_ttl_ms: validFormValues.inactivity_ttl_ms * 86400000,
}),
),
)
})

it("allows a default ttl of 7 days", () => {
const values: UpdateTemplateMeta = {
...validFormValues,
default_ttl_ms: 24 * 7,
Expand All @@ -101,7 +141,7 @@ describe("TemplateSchedulePage", () => {
expect(validate).not.toThrowError()
})

it("allows ttl of 0", () => {
it("allows default ttl of 0", () => {
const values: UpdateTemplateMeta = {
...validFormValues,
default_ttl_ms: 0,
Expand All @@ -110,7 +150,7 @@ describe("TemplateSchedulePage", () => {
expect(validate).not.toThrowError()
})

it("disallows a ttl of 7 days + 1 hour", () => {
it("disallows a default ttl of 7 days + 1 hour", () => {
const values: UpdateTemplateMeta = {
...validFormValues,
default_ttl_ms: 24 * 7 + 1,
Expand All @@ -120,4 +160,62 @@ describe("TemplateSchedulePage", () => {
t("defaultTTLMaxError", { ns: "templateSettingsPage" }),
)
})

it("allows a failure ttl of 7 days", () => {
const values: UpdateTemplateMeta = {
...validFormValues,
failure_ttl_ms: 86400000 * 7,
}
const validate = () => getValidationSchema().validateSync(values)
expect(validate).not.toThrowError()
})

it("allows failure ttl of 0", () => {
const values: UpdateTemplateMeta = {
...validFormValues,
failure_ttl_ms: 0,
}
const validate = () => getValidationSchema().validateSync(values)
expect(validate).not.toThrowError()
})

it("disallows a negative failure ttl", () => {
const values: UpdateTemplateMeta = {
...validFormValues,
failure_ttl_ms: -1,
}
const validate = () => getValidationSchema().validateSync(values)
expect(validate).toThrowError(
"Failure cleanup days must not be less than 0.",
)
})

it("allows an inactivity ttl of 7 days", () => {
const values: UpdateTemplateMeta = {
...validFormValues,
inactivity_ttl_ms: 86400000 * 7,
}
const validate = () => getValidationSchema().validateSync(values)
expect(validate).not.toThrowError()
})

it("allows an inactivity ttl of 0", () => {
const values: UpdateTemplateMeta = {
...validFormValues,
inactivity_ttl_ms: 0,
}
const validate = () => getValidationSchema().validateSync(values)
expect(validate).not.toThrowError()
})

it("disallows a negative inactivity ttl", () => {
const values: UpdateTemplateMeta = {
...validFormValues,
inactivity_ttl_ms: -1,
}
const validate = () => getValidationSchema().validateSync(values)
expect(validate).toThrowError(
"Inactivity cleanup days must not be less than 0.",
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default {
component: TemplateSchedulePageView,
args: {
allowAdvancedScheduling: true,
allowWorkspaceActions: true,
template: MockTemplate,
onSubmit: action("onSubmit"),
onCancel: action("cancel"),
Expand Down
2 changes: 1 addition & 1 deletion site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ export const MockEntitlementsWithScheduling: TypesGen.Entitlements = {
}),
}

export const MockExperiments: TypesGen.Experiment[] = []
export const MockExperiments: TypesGen.Experiment[] = ["workspace_actions"]

export const MockAuditLog: TypesGen.AuditLog = {
id: "fbd2116a-8961-4954-87ae-e4575bd29ce0",
Expand Down