mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-04 21:49:25 +00:00
* Initial plan * feat: refactor option validation to list-based approach and add delete+hide_and_recreate check Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com> * feat: add only_update to exclusive modes validation list Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com> * refactor: extract validation logic into src/validate.ts Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com> * refactor: move validateExclusiveModes before getBody in run() Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com> * test: assert getBody is not called when validateExclusiveModes fails Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com>
85 lines
3.5 KiB
TypeScript
85 lines
3.5 KiB
TypeScript
import {describe, expect, test} from "vitest"
|
|
import {validateBody, validateExclusiveModes} from "../src/validate"
|
|
|
|
describe("validateBody", () => {
|
|
test("throws when body is empty and neither delete nor hide is set", () => {
|
|
expect(() => validateBody("", false, false)).toThrow(
|
|
"Either message or path input is required",
|
|
)
|
|
})
|
|
|
|
test("does not throw when body is provided", () => {
|
|
expect(() => validateBody("some body", false, false)).not.toThrow()
|
|
})
|
|
|
|
test("does not throw when body is empty but deleteOldComment is true", () => {
|
|
expect(() => validateBody("", true, false)).not.toThrow()
|
|
})
|
|
|
|
test("does not throw when body is empty but hideOldComment is true", () => {
|
|
expect(() => validateBody("", false, true)).not.toThrow()
|
|
})
|
|
})
|
|
|
|
describe("validateExclusiveModes", () => {
|
|
test("does not throw when no modes are enabled", () => {
|
|
expect(() => validateExclusiveModes(false, false, false, false, false, false)).not.toThrow()
|
|
})
|
|
|
|
test("does not throw when exactly one mode is enabled", () => {
|
|
expect(() => validateExclusiveModes(true, false, false, false, false, false)).not.toThrow()
|
|
expect(() => validateExclusiveModes(false, true, false, false, false, false)).not.toThrow()
|
|
expect(() => validateExclusiveModes(false, false, true, false, false, false)).not.toThrow()
|
|
expect(() => validateExclusiveModes(false, false, false, true, false, false)).not.toThrow()
|
|
expect(() => validateExclusiveModes(false, false, false, false, true, false)).not.toThrow()
|
|
expect(() => validateExclusiveModes(false, false, false, false, false, true)).not.toThrow()
|
|
})
|
|
|
|
test("throws when delete and recreate are both true", () => {
|
|
expect(() => validateExclusiveModes(true, true, false, false, false, false)).toThrow(
|
|
"delete and recreate cannot be set to true simultaneously",
|
|
)
|
|
})
|
|
|
|
test("throws when delete and only_create are both true", () => {
|
|
expect(() => validateExclusiveModes(true, false, true, false, false, false)).toThrow(
|
|
"delete and only_create cannot be set to true simultaneously",
|
|
)
|
|
})
|
|
|
|
test("throws when delete and only_update are both true", () => {
|
|
expect(() => validateExclusiveModes(true, false, false, true, false, false)).toThrow(
|
|
"delete and only_update cannot be set to true simultaneously",
|
|
)
|
|
})
|
|
|
|
test("throws when delete and hide are both true", () => {
|
|
expect(() => validateExclusiveModes(true, false, false, false, true, false)).toThrow(
|
|
"delete and hide cannot be set to true simultaneously",
|
|
)
|
|
})
|
|
|
|
test("throws when delete and hide_and_recreate are both true", () => {
|
|
expect(() => validateExclusiveModes(true, false, false, false, false, true)).toThrow(
|
|
"delete and hide_and_recreate cannot be set to true simultaneously",
|
|
)
|
|
})
|
|
|
|
test("throws when only_create and only_update are both true", () => {
|
|
expect(() => validateExclusiveModes(false, false, true, true, false, false)).toThrow(
|
|
"only_create and only_update cannot be set to true simultaneously",
|
|
)
|
|
})
|
|
|
|
test("throws when hide and hide_and_recreate are both true", () => {
|
|
expect(() => validateExclusiveModes(false, false, false, false, true, true)).toThrow(
|
|
"hide and hide_and_recreate cannot be set to true simultaneously",
|
|
)
|
|
})
|
|
|
|
test("uses Oxford comma when three or more modes are enabled", () => {
|
|
expect(() => validateExclusiveModes(true, true, true, false, false, false)).toThrow(
|
|
"delete, recreate, and only_create cannot be set to true simultaneously",
|
|
)
|
|
})
|
|
})
|