|
| 1 | +const { default: route } = await import( |
| 2 | + "../../../build/routes/monitor/usage.js" |
| 3 | +); |
| 4 | + |
| 5 | +function mockRes() { |
| 6 | + const res = { |
| 7 | + _status: 200, |
| 8 | + _body: undefined, |
| 9 | + _headers: {}, |
| 10 | + status(code) { res._status = code; return res; }, |
| 11 | + json(body) { res._body = body; return res; }, |
| 12 | + set(header, value) { res._headers[header] = value; return res; }, |
| 13 | + }; |
| 14 | + return res; |
| 15 | +} |
| 16 | + |
| 17 | +describe("monitor/usage", () => { |
| 18 | + it("returns all required fields with correct types", () => { |
| 19 | + const res = mockRes(); |
| 20 | + route({}, res); |
| 21 | + expect(res._body).toBeDefined(); |
| 22 | + expect(typeof res._body.name).toBe("string"); |
| 23 | + expect(typeof res._body.version).toBe("string"); |
| 24 | + expect(typeof res._body.uptime).toBe("number"); |
| 25 | + expect(typeof res._body.heapUsed).toBe("number"); |
| 26 | + expect(typeof res._body.heapTotal).toBe("number"); |
| 27 | + }); |
| 28 | + |
| 29 | + it("returns respec.org as the service name", () => { |
| 30 | + const res = mockRes(); |
| 31 | + route({}, res); |
| 32 | + expect(res._body.name).toBe("respec.org"); |
| 33 | + }); |
| 34 | + |
| 35 | + it("sets Cache-Control to no-store", () => { |
| 36 | + const res = mockRes(); |
| 37 | + route({}, res); |
| 38 | + expect(res._headers["Cache-Control"]).toBe("no-store"); |
| 39 | + }); |
| 40 | + |
| 41 | + it("returns positive uptime", () => { |
| 42 | + const res = mockRes(); |
| 43 | + route({}, res); |
| 44 | + expect(res._body.uptime).toBeGreaterThan(0); |
| 45 | + }); |
| 46 | + |
| 47 | + it("returns positive heap values", () => { |
| 48 | + const res = mockRes(); |
| 49 | + route({}, res); |
| 50 | + expect(res._body.heapUsed).toBeGreaterThan(0); |
| 51 | + expect(res._body.heapTotal).toBeGreaterThan(0); |
| 52 | + expect(res._body.heapTotal).toBeGreaterThanOrEqual(res._body.heapUsed); |
| 53 | + }); |
| 54 | +}); |
0 commit comments