gitlab_monitor/test/checkpath.test.ts
zhaoyingbo 713b67a52c
All checks were successful
CI Monitor MIflow / build-image (push) Successful in 44s
feat: 修复路径匹配失败
2024-08-09 02:02:05 +00:00

30 lines
1.0 KiB
TypeScript

import { expect, test } from "bun:test"
import { makeCheckPathTool } from "../utils/pathTools"
test("makeCheckPathTool exactCheck", () => {
const tool = makeCheckPathTool("https://example.com/base")
expect(tool.exactCheck("/base")).toBe(true)
expect(tool.exactCheck("/base/extra")).toBe(false)
})
test("makeCheckPathTool startsWithCheck", () => {
const tool = makeCheckPathTool("https://example.com/base")
expect(tool.startsWithCheck("/base")).toBe(true)
expect(tool.startsWithCheck("/base/extra")).toBe(false)
expect(tool.startsWithCheck("/other")).toBe(false)
})
test("makeCheckPathTool fullCheck", () => {
const tool = makeCheckPathTool("https://example.com/")
expect(tool.fullCheck("/")).toBe(true)
expect(tool.fullCheck("/base")).toBe(false)
})
test("makeCheckPathTool with prefix", () => {
const tool = makeCheckPathTool("https://example.com/prefix/base", "/prefix")
expect(tool.exactCheck("/base")).toBe(true)
expect(tool.startsWithCheck("/base")).toBe(true)
expect(tool.fullCheck("/prefix")).toBe(false)
})