-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 🚧 checker api * 🚧 single check * 🚧 single check * 🧪 fix test * 🧪 fix tests * 🧪 fix tests * 🧪 * 🧪 fix tests * 🧪 fix tests * 🧪 add tests * 🛂 pr * 📝 format
- Loading branch information
1 parent
82ec6bf
commit 5d867bb
Showing
25 changed files
with
3,026 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { OpenAPIHono } from "@hono/zod-openapi"; | ||
|
||
import type { Variables } from "../index"; | ||
|
||
import { handleZodError } from "../../libs/errors"; | ||
import { registerPostCheck } from "./post"; | ||
|
||
const checkAPI = new OpenAPIHono<{ Variables: Variables }>({ | ||
defaultHook: handleZodError, | ||
}); | ||
|
||
registerPostCheck(checkAPI); | ||
|
||
export { checkAPI }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import { expect, test } from "bun:test"; | ||
|
||
import { api } from "../index"; | ||
|
||
import { afterEach, mock } from "bun:test"; | ||
|
||
const mockFetch = mock(); | ||
|
||
global.fetch = mockFetch; | ||
mock.module("node-fetch", () => mockFetch); | ||
|
||
afterEach(() => { | ||
mockFetch.mockReset(); | ||
}); | ||
|
||
test("Create a single check ", async () => { | ||
const data = { | ||
url: "https://www.openstatus.dev", | ||
regions: ["ams"], | ||
method: "POST", | ||
body: '{"hello":"world"}', | ||
headers: [{ key: "key", value: "value" }], | ||
}; | ||
mockFetch.mockReturnValue( | ||
Promise.resolve( | ||
new Response( | ||
'{"status":200,"latency":100,"body":"Hello World","headers":{"Content-Type":"application/json"},"timestamp":1234567890,"timing":{"dnsStart":1,"dnsDone":2,"connectStart":3,"connectDone":4,"tlsHandshakeStart":5,"tlsHandshakeDone":6,"firstByteStart":7,"firstByteDone":8,"transferStart":9,"transferDone":10},"region":"ams"}', | ||
{ status: 200, headers: { "content-type": "application/json" } }, | ||
), | ||
), | ||
); | ||
|
||
const res = await api.request("/check", { | ||
method: "POST", | ||
headers: { | ||
"x-openstatus-key": "1", | ||
"content-type": "application/json", | ||
}, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
expect(res.status).toBe(200); | ||
|
||
expect(await res.json()).toMatchObject({ | ||
id: expect.any(Number), | ||
raw: [ | ||
{ | ||
connectDone: 4, | ||
connectStart: 3, | ||
dnsDone: 2, | ||
dnsStart: 1, | ||
firstByteDone: 8, | ||
firstByteStart: 7, | ||
tlsHandshakeDone: 6, | ||
tlsHandshakeStart: 5, | ||
transferDone: 10, | ||
transferStart: 9, | ||
}, | ||
], | ||
response: { | ||
body: "Hello World", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
latency: 100, | ||
region: "ams", | ||
status: 200, | ||
timestamp: 1234567890, | ||
timing: { | ||
connectDone: 4, | ||
connectStart: 3, | ||
dnsDone: 2, | ||
dnsStart: 1, | ||
firstByteDone: 8, | ||
firstByteStart: 7, | ||
tlsHandshakeDone: 6, | ||
tlsHandshakeStart: 5, | ||
transferDone: 10, | ||
transferStart: 9, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
test.todo("Create a multiple check ", async () => { | ||
const data = { | ||
url: "https://www.openstatus.dev", | ||
regions: ["ams", "gru"], | ||
method: "POST", | ||
body: '{"hello":"world"}', | ||
headers: [{ key: "key", value: "value" }], | ||
}; | ||
mockFetch.mockReturnValue( | ||
Promise.resolve( | ||
new Response( | ||
'{"status":200,"latency":100,"body":"Hello World","headers":{"Content-Type":"application/json"},"timestamp":1234567890,"timing":{"dnsStart":1,"dnsDone":2,"connectStart":3,"connectDone":4,"tlsHandshakeStart":5,"tlsHandshakeDone":6,"firstByteStart":7,"firstByteDone":8,"transferStart":9,"transferDone":10},"region":"ams"}', | ||
{ status: 200, headers: { "content-type": "application/json" } }, | ||
), | ||
), | ||
); | ||
|
||
const res = await api.request("/check", { | ||
method: "POST", | ||
headers: { | ||
"x-openstatus-key": "1", | ||
"content-type": "application/json", | ||
}, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
expect(res.status).toBe(200); | ||
|
||
expect(await res.json()).toMatchObject({ | ||
id: expect.any(Number), | ||
raw: [ | ||
{ | ||
connectDone: 4, | ||
connectStart: 3, | ||
dnsDone: 2, | ||
dnsStart: 1, | ||
firstByteDone: 8, | ||
firstByteStart: 7, | ||
tlsHandshakeDone: 6, | ||
tlsHandshakeStart: 5, | ||
transferDone: 10, | ||
transferStart: 9, | ||
}, | ||
], | ||
response: { | ||
body: "Hello World", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
latency: 100, | ||
region: "ams", | ||
status: 200, | ||
timestamp: 1234567890, | ||
timing: { | ||
connectDone: 4, | ||
connectStart: 3, | ||
dnsDone: 2, | ||
dnsStart: 1, | ||
firstByteDone: 8, | ||
firstByteStart: 7, | ||
tlsHandshakeDone: 6, | ||
tlsHandshakeStart: 5, | ||
transferDone: 10, | ||
transferStart: 9, | ||
}, | ||
}, | ||
}); | ||
}); |
Oops, something went wrong.