Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Enhance ] Status Report Endpoint to Support Additional Params and Return Neccessary Details #760

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
012c9d4
enhance: create, get and get-all status report endpoints
Nabhag8848 Apr 9, 2024
c0bd619
enhance: update status report endpoint with error handling
Nabhag8848 Apr 10, 2024
05fb4b7
fix: create report to handle non exisiting monitor and pages id
Nabhag8848 Apr 10, 2024
447d0ac
test: added more data for seeding database
Nabhag8848 Apr 10, 2024
0aab00f
fix: update report to give appriopriate error message and code
Nabhag8848 Apr 10, 2024
4d6b3b9
test: added test for statusReport
Nabhag8848 Apr 10, 2024
2359b0f
enhance: seeding to insert multiple records
Nabhag8848 Apr 10, 2024
8b126de
fix: openapi defination to have optional field
Nabhag8848 Apr 11, 2024
f730606
fix: eslint warnings
Nabhag8848 Apr 11, 2024
d2509e6
fix: create report date issue
Nabhag8848 Apr 20, 2024
fefe412
fix(test): status page router
Nabhag8848 May 8, 2024
efb8014
fix: statusReportUpdate endpoint test
Nabhag8848 May 8, 2024
64fd617
fix: more status report cases
Nabhag8848 May 8, 2024
7cc1544
fix: all statusReport test
Nabhag8848 May 8, 2024
e6990cf
🔥 Improve rum page (#843)
thibaultleouay May 30, 2024
5275336
🔥 feat: posthog (#842)
mxkaske May 30, 2024
3b65769
🌐 improve metadata
thibaultleouay May 30, 2024
ff4c4ba
🌐 improve metadata
thibaultleouay May 30, 2024
e175b5b
🎥 add video (#844)
thibaultleouay May 30, 2024
f0f5108
🐛 fix badge size (#845)
thibaultleouay May 30, 2024
9422a6c
🔥 Add inp (#846)
thibaultleouay May 31, 2024
cd1815d
Merge branch 'main' into fix/status-report-api
thibaultleouay May 31, 2024
18152bb
Merge branch 'refactor/api-server-with-errors' into Nabhag8848-status…
mxkaske Jun 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/docs/synthetic/features/monitor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ We currently support the following assertions on the following fields:

- **Status Code**
- **Response Body**

## Video Tutorial 📺

<iframe width="560" height="315" src="https://www.youtube.com/embed/nYti3DjHoWY?si=RBGFHzoHFmwphRft" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
12 changes: 12 additions & 0 deletions apps/docs/synthetic/features/status-page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ If you want the dark version of the badge, you can use the following URL:
```html
<img src="https://YOUR-SLUG.openstatus.dev/badge?theme=dark" />
```

You can also customize the size of the badge by adding a `size` parameter:

- `sm
- `md`
- `lg`
- `xl`


```html
<img src="https://YOUR-SLUG.openstatus.dev/badge?theme=dark&size=xl" />
```
2 changes: 2 additions & 0 deletions apps/ingest-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ app.post("/v1", async (c) => {
const data = z.array(schemaV1).parse(JSON.parse(rawText));
const userAgent = c.req.header("user-agent") || "";

const timestamp = Date.now();
const country = c.req.header("cf-ipcountry") || "";
const city = c.req.raw.cf?.city || "";
const region_code = c.req.raw.cf?.regionCode || "";
Expand All @@ -130,6 +131,7 @@ app.post("/v1", async (c) => {
const device = getDevice(d.screen, os);
return tbIngestWebVitals.parse({
...d,
timestamp,
device,
...d.data,
browser,
Expand Down
12 changes: 7 additions & 5 deletions apps/ingest-worker/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export function getDevice(screen: string, os: string) {
return "laptop";
}
return "desktop";
} else if (MOBILE_OS.includes(os)) {
}
if (MOBILE_OS.includes(os)) {
if (os === "Amazon OS" || +width > MOBILE_SCREEN_WIDTH) {
return "tablet";
}
Expand All @@ -54,11 +55,12 @@ export function getDevice(screen: string, os: string) {

if (+width >= DESKTOP_SCREEN_WIDTH) {
return "desktop";
} else if (+width >= LAPTOP_SCREEN_WIDTH) {
}
if (+width >= LAPTOP_SCREEN_WIDTH) {
return "laptop";
} else if (+width >= MOBILE_SCREEN_WIDTH) {
}
if (+width >= MOBILE_SCREEN_WIDTH) {
return "tablet";
} else {
return "mobile";
}
return "mobile";
}
239 changes: 195 additions & 44 deletions apps/server/src/v1/statusReport.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect, test } from "bun:test";

import { api } from ".";
import { iso8601Regex } from "./test-utils";

test("GET one status report", async () => {
const res = await api.request("/status_report/1", {
Expand All @@ -12,12 +11,47 @@ test("GET one status report", async () => {
expect(res.status).toBe(200);
expect(await res.json()).toMatchObject({
id: 1,
// TODO: discuss if we should return `updates` instead of `status_report_updates`
status_report_updates: expect.any(Array),
title: "Test Status Report",
status: "monitoring",
status_report_updates: [1, 3, 4],
message: "test",
monitors_id: null,
pages_id: [1],
});
});

test("create one status report", async () => {
test("Get all status report", async () => {
const res = await api.request("/status_report", {
headers: {
"x-openstatus-key": "1",
},
});
expect(res.status).toBe(200);
expect({ data: await res.json() }).toMatchObject({
data: [
{
id: 1,
title: "Test Status Report",
status: "monitoring",
status_report_updates: [1, 3, 4],
message: "test",
monitors_id: null,
pages_id: [1],
},
{
id: 2,
title: "Test Status Report",
status: "investigating",
status_report_updates: [2],
message: "Message",
monitors_id: [1, 2],
pages_id: [1],
},
],
});
});

test("Create one status report including passing optional fields", async () => {
const res = await api.request("/status_report", {
method: "POST",
headers: {
Expand All @@ -26,13 +60,21 @@ test("create one status report", async () => {
},
body: JSON.stringify({
status: "investigating",
title: "Test Status Report",
title: "New Status Report",
message: "Message",
monitors_id: [1],
pages_id: [1],
}),
});
expect(res.status).toBe(200);
expect(await res.json()).toMatchObject({
id: expect.any(Number),
status_report_updates: expect.any(Array),
id: 3,
title: "New Status Report",
status: "investigating",
status_report_updates: [5],
message: "Message",
monitors_id: [1],
pages_id: [1],
});
});

Expand Down Expand Up @@ -72,21 +114,54 @@ test("Create one status report with invalid data should return 403", async () =>
});
});

test("Get all status report", async () => {
test("Create status report with non existing monitor ids should return 400", async () => {
const res = await api.request("/status_report", {
method: "POST",
headers: {
"x-openstatus-key": "1",
"content-type": "application/json",
},
body: JSON.stringify({
status: "investigating",
title: "New Status Report",
message: "Message",
monitors_id: [100],
pages_id: [1],
}),
});
expect(res.status).toBe(200);
expect((await res.json())[0]).toMatchObject({
id: expect.any(Number),
status_report_updates: expect.any(Array),

expect(res.status).toBe(400);
expect(await res.json()).toMatchObject({
code: 400,
message: "monitor(s) with id [100] doesn't exist ",
});
});

test("Create status report with non existing page ids should return 400", async () => {
const res = await api.request("/status_report", {
method: "POST",
headers: {
"x-openstatus-key": "1",
"content-type": "application/json",
},
body: JSON.stringify({
status: "investigating",
title: "New Status Report",
message: "Message",
monitors_id: [1],
pages_id: [100],
}),
});

expect(res.status).toBe(400);
expect(await res.json()).toMatchObject({
code: 400,
message: "page(s) with id [100] doesn't exist ",
});
});

test("Delete a status report", async () => {
const res = await api.request("/status_report/2", {
const res = await api.request("/status_report/3", {
method: "DELETE",
headers: {
"x-openstatus-key": "1",
Expand All @@ -97,8 +172,29 @@ test("Delete a status report", async () => {
message: "Deleted",
});
});
test("create a status report update with empty body should return current report info", async () => {
const res = await api.request("/status_report/1/update", {
method: "POST",
headers: {
"x-openstatus-key": "1",
"content-type": "application/json",
},
body: JSON.stringify({}),
});

test("create a status report update", async () => {
expect(res.status).toBe(200);
expect(await res.json()).toMatchObject({
id: 1,
title: "Test Status Report",
status: "investigating",
status_report_updates: [1, 3, 4],
message: "test",
monitors_id: null,
pages_id: [1],
});
});

test("Create status report update with non existing monitor ids should return 400", async () => {
const res = await api.request("/status_report/1/update", {
method: "POST",
headers: {
Expand All @@ -107,16 +203,94 @@ test("create a status report update", async () => {
},
body: JSON.stringify({
status: "investigating",
date: "2023-11-08T21:03:13.000Z",
message: "Test Status Report",
title: "New Status Report",
message: "Message",
monitors_id: [100],
pages_id: [1],
}),
});

expect(res.status).toBe(400);
expect(await res.json()).toMatchObject({
code: 400,
message: "monitor(s) with id [100] doesn't exist ",
});
});

test("Create status report update with non existing page ids should return 400", async () => {
const res = await api.request("/status_report/1/update", {
method: "POST",
headers: {
"x-openstatus-key": "1",
"content-type": "application/json",
},
body: JSON.stringify({
status: "investigating",
title: "New Status Report",
message: "Message",
monitors_id: [1],
pages_id: [100],
}),
});

expect(res.status).toBe(400);
expect(await res.json()).toMatchObject({
code: 400,
message: "page(s) with id [100] doesn't exist ",
});
});

test("Update with title, monitor & page should not create record in status_report_update table", async () => {
const res = await api.request("/status_report/1/update", {
method: "POST",
headers: {
"x-openstatus-key": "1",
"content-type": "application/json",
},
body: JSON.stringify({
title: "Doesn't add record",
monitors_id: [1],
pages_id: [],
}),
});

expect(res.status).toBe(200);
expect(await res.json()).toMatchObject({
id: 1,
title: "Doesn't add record",
status: "investigating",
id: expect.any(String),
date: expect.stringMatching(iso8601Regex),
message: "Test Status Report",
status_report_updates: [1, 3, 4],
message: "test",
monitors_id: [1],
pages_id: null,
});
});

test("create a status report update", async () => {
const res = await api.request("/status_report/1/update", {
method: "POST",
headers: {
"x-openstatus-key": "1",
"content-type": "application/json",
},
body: JSON.stringify({
title: "Updated Status Report",
status: "resolved",
message: "New Message",
monitors_id: [1, 2],
pages_id: [],
}),
});
expect(res.status).toBe(200);

expect(await res.json()).toMatchObject({
id: 1,
title: "Updated Status Report",
status: "resolved",
status_report_updates: [1, 3, 4, 5],
message: "New Message",
monitors_id: [1, 2],
pages_id: null,
});
});

Expand All @@ -129,7 +303,7 @@ test("Get Status Report should return current status of report", async () => {
expect(res.status).toBe(200);
expect(await res.json()).toMatchObject({
id: 1,
status: "investigating",
status: "resolved",
status_report_updates: expect.any(Array),
});
});
Expand All @@ -150,7 +324,7 @@ test("Create a status report update not in db should return 404", async () => {
expect(res.status).toBe(404);
expect(await res.json()).toMatchObject({
code: 404,
message: "Not Found",
message: `status report with id 404 doesn't exist`,
});
});

Expand All @@ -169,26 +343,3 @@ test("Create a status report update without auth key should return 401", async (
});
expect(res.status).toBe(401);
});

test("Create a status report update with invalid data should return 403", async () => {
const res = await api.request("/status_report/1/update", {
method: "POST",
headers: {
"x-openstatus-key": "1",
"content-type": "application/json",
},
body: JSON.stringify({
//passing in incompelete body
date: "2023-11-08T21:03:13.000Z",
message: "Test Status Report",
}),
});
expect(res.status).toBe(400);
expect(await res.json()).toMatchObject({
error: {
issues: expect.any(Array),
name: "ZodError",
},
success: false,
});
});
Loading
Loading