feat: unit tests for security/utility functions (isPrivateIP, isTransientError, markdown, escapeHtml)
This commit is contained in:
parent
0a002f94ef
commit
50a163b12d
10 changed files with 224 additions and 62 deletions
50
src/__tests__/markdown.test.ts
Normal file
50
src/__tests__/markdown.test.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { markdownToHtml, wrapHtml } from "../services/markdown.js";
|
||||
|
||||
describe("markdownToHtml", () => {
|
||||
it("converts headings", () => {
|
||||
expect(markdownToHtml("# Hello")).toContain("<h1>Hello</h1>");
|
||||
});
|
||||
it("converts bold", () => {
|
||||
expect(markdownToHtml("**bold**")).toContain("<strong>bold</strong>");
|
||||
});
|
||||
it("converts italic", () => {
|
||||
expect(markdownToHtml("*italic*")).toContain("<em>italic</em>");
|
||||
});
|
||||
it("converts links", () => {
|
||||
expect(markdownToHtml("[link](http://x.com)")).toContain('<a href="http://x.com">link</a>');
|
||||
});
|
||||
it("converts code blocks", () => {
|
||||
expect(markdownToHtml("```\ncode\n```")).toContain("<code>");
|
||||
});
|
||||
it("handles empty string", () => {
|
||||
const result = markdownToHtml("");
|
||||
expect(result).toContain("<!DOCTYPE html>");
|
||||
});
|
||||
it("applies custom CSS", () => {
|
||||
const result = markdownToHtml("# Hi", "body{color:red}");
|
||||
expect(result).toContain("body{color:red}");
|
||||
});
|
||||
it("uses default CSS when none provided", () => {
|
||||
const result = markdownToHtml("# Hi");
|
||||
expect(result).toContain("font-family");
|
||||
});
|
||||
});
|
||||
|
||||
describe("wrapHtml", () => {
|
||||
it("wraps body in HTML document structure", () => {
|
||||
const result = wrapHtml("<p>test</p>");
|
||||
expect(result).toContain("<!DOCTYPE html>");
|
||||
expect(result).toContain("<body><p>test</p></body>");
|
||||
});
|
||||
it("applies custom CSS", () => {
|
||||
expect(wrapHtml("<p>x</p>", "h1{color:blue}")).toContain("h1{color:blue}");
|
||||
});
|
||||
it("uses default CSS when none provided", () => {
|
||||
expect(wrapHtml("<p>x</p>")).toContain("font-family");
|
||||
});
|
||||
it("handles empty string body", () => {
|
||||
const result = wrapHtml("");
|
||||
expect(result).toContain("<body></body>");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue