gitlab_monitor/test/manageGitlabEventReq.test.ts
zhaoyingbo 3471576ed7
All checks were successful
CI Monitor MIflow / build-image (push) Successful in 47s
feat: 修改打印逻辑 & 请求等待结果
2024-08-09 03:40:37 +00:00

65 lines
1.5 KiB
TypeScript

import { expect, test } from "bun:test"
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 res = await manageGitlabEventReq(req)
expect(res).toEqual(netTool.ok())
})