@stanlemon/server 0.3.46 → 0.3.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.js +1 -1
- package/app.test.js +52 -0
- package/package.json +2 -2
package/app.js
CHANGED
package/app.test.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
import request from "supertest";
|
|
5
|
+
import { app } from "./app.js";
|
|
6
|
+
|
|
7
|
+
describe("/app", () => {
|
|
8
|
+
it("GET /hello", async () => {
|
|
9
|
+
// Happy path 200 use case
|
|
10
|
+
const response = await request(app)
|
|
11
|
+
.get("/hello")
|
|
12
|
+
.set("Accept", "application/json");
|
|
13
|
+
|
|
14
|
+
expect(response.headers["content-type"]).toMatch(/json/);
|
|
15
|
+
expect(response.status).toEqual(200);
|
|
16
|
+
expect(response.body).toEqual({ hello: "Stan" });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("GET /hello/Stan", async () => {
|
|
20
|
+
// This endpoint explicitly 404s
|
|
21
|
+
const response = await request(app)
|
|
22
|
+
.get("/hello/Stan")
|
|
23
|
+
.set("Accept", "application/json");
|
|
24
|
+
|
|
25
|
+
expect(response.headers["content-type"]).toMatch(/json/);
|
|
26
|
+
expect(response.status).toEqual(404);
|
|
27
|
+
expect(response.body).toEqual({ error: "Not Found" });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("GET /hello/Sara", async () => {
|
|
31
|
+
// Custom parameter 200
|
|
32
|
+
const response = await request(app)
|
|
33
|
+
.get("/hello/Sara")
|
|
34
|
+
.set("Accept", "application/json");
|
|
35
|
+
|
|
36
|
+
expect(response.headers["content-type"]).toMatch(/json/);
|
|
37
|
+
expect(response.status).toEqual(200);
|
|
38
|
+
expect(response.body).toEqual({ hello: "Sara" });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("POST /hello", async () => {
|
|
42
|
+
// POST request with JSON body 200
|
|
43
|
+
const response = await request(app)
|
|
44
|
+
.post("/hello")
|
|
45
|
+
.set("Accept", "application/json")
|
|
46
|
+
.send({ name: "Henry" });
|
|
47
|
+
|
|
48
|
+
expect(response.headers["content-type"]).toMatch(/json/);
|
|
49
|
+
expect(response.status).toEqual(200);
|
|
50
|
+
expect(response.body).toEqual({ hello: "Henry" });
|
|
51
|
+
});
|
|
52
|
+
});
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stanlemon/server",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.47",
|
|
4
4
|
"description": "A basic express web server setup.",
|
|
5
5
|
"author": "Stan Lemon <stanlemon@users.noreply.github.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=22.
|
|
8
|
+
"node": ">=22.14.0"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"main": "./src/index.js",
|