forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhealth-payload.test.ts
More file actions
27 lines (22 loc) · 923 Bytes
/
Copy pathhealth-payload.test.ts
File metadata and controls
27 lines (22 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import request from "supertest";
import { describe, expect, it } from "vitest";
import { createApp } from "../src/app";
describe("health payload contract", () => {
const app = createApp();
it("returns all required fields with correct types and values", async () => {
const before = Date.now();
const response = await request(app).get("/api/v1/health");
const after = Date.now();
expect(response.status).toBe(200);
expect(response.body.success).toBe(true);
expect(response.body.data.status).toBe("ok");
expect(response.body.data.service).toBe("Lily Backend");
expect(["development", "test", "production"]).toContain(
response.body.data.environment,
);
const ts = new Date(response.body.data.timestamp).getTime();
expect(Number.isNaN(ts)).toBe(false);
expect(ts).toBeGreaterThanOrEqual(before - 1000);
expect(ts).toBeLessThanOrEqual(after + 1000);
});
});