import { expect, test } from "bun:test" import loggerIns from "../log" import { manageGitlabEventReq } from "../routes/event" import netTool from "../service/netTool" import { Gitlab } from "../types/gitlab" test("manageGitlabEventReq", async () => { const headers = new Headers({ "x-gitlab-token": "uwnpzb9hvoft28h", "x-gitlab-event": "Pipeline Hook", }) const body: Gitlab.PipelineEvent = { object_attributes: { id: 12345, ref: "main", sha: "abc123def456", status: "success", created_at: "2023-10-01T12:00:00Z", finished_at: "2023-10-01T12:05:00Z", duration: 300, }, user: { name: "John Doe", username: "zhaoyingbo", }, project: { id: 67890, web_url: "https://gitlab.example.com/johndoe/project", path_with_namespace: "johndoe/project", }, commit: { id: "abc123def456", title: "Fix bug in pipeline", url: "https://gitlab.example.com/johndoe/project/commit/abc123def456", }, builds: [ { id: 111, stage: "build", status: "success", finished_at: "2023-10-01T12:02:00Z", }, { id: 112, stage: "test", status: "success", finished_at: "2023-10-01T12:04:00Z", }, ], } const req = new Request( "https://lark-egg.ai.xiaomi.com/gitlab_monitor/event", { method: "POST", headers: headers, body: JSON.stringify(body), } ) const logger = loggerIns.child({ name: "test" }) const res = await manageGitlabEventReq(req, logger) expect(res).toEqual(netTool.ok()) })