@stanlemon/app-template 0.3.80 → 0.3.83
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.test.js +24 -7
- package/package.json +4 -4
- package/src/App.test.tsx +19 -14
- package/src/index.tsx +6 -3
package/app.test.js
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import request from "supertest";
|
|
5
5
|
import { app, db } from "./app.js";
|
|
6
|
+
import { test__signupAndLogin } from "@stanlemon/server-with-auth";
|
|
7
|
+
|
|
8
|
+
async function signupAndLogin() {
|
|
9
|
+
const { token } = await test__signupAndLogin(
|
|
10
|
+
app,
|
|
11
|
+
"test" + Math.random(),
|
|
12
|
+
"p@$$w0rd!",
|
|
13
|
+
{ name: "Test User", email: "test@test.com" }
|
|
14
|
+
);
|
|
15
|
+
return token;
|
|
16
|
+
}
|
|
6
17
|
|
|
7
18
|
describe("/app", () => {
|
|
8
19
|
afterEach(() => {
|
|
@@ -11,40 +22,46 @@ describe("/app", () => {
|
|
|
11
22
|
});
|
|
12
23
|
|
|
13
24
|
it("lists items", async () => {
|
|
25
|
+
const token = await signupAndLogin();
|
|
14
26
|
const response = await request(app)
|
|
15
27
|
.get("/api/items")
|
|
16
|
-
.set("Accept", "application/json")
|
|
28
|
+
.set("Accept", "application/json")
|
|
29
|
+
.set("Authorization", "Bearer " + token);
|
|
17
30
|
|
|
18
|
-
expect(response.headers["content-type"]).toMatch(/json/);
|
|
19
31
|
expect(response.status).toEqual(200);
|
|
32
|
+
expect(response.headers["content-type"]).toMatch(/json/);
|
|
20
33
|
expect(response.body).toEqual([]);
|
|
21
34
|
});
|
|
22
35
|
|
|
23
36
|
it("add item", async () => {
|
|
37
|
+
const token = await signupAndLogin();
|
|
24
38
|
const response = await request(app)
|
|
25
39
|
.post("/api/items")
|
|
26
40
|
.set("Accept", "application/json")
|
|
27
|
-
.send({ item: "hello world" })
|
|
41
|
+
.send({ item: "hello world" })
|
|
42
|
+
.set("Authorization", "Bearer " + token);
|
|
28
43
|
|
|
29
|
-
expect(response.headers["content-type"]).toMatch(/json/);
|
|
30
44
|
expect(response.status).toEqual(200);
|
|
45
|
+
expect(response.headers["content-type"]).toMatch(/json/);
|
|
31
46
|
expect(response.body).toMatchObject([{ item: "hello world" }]);
|
|
32
47
|
});
|
|
33
48
|
|
|
34
49
|
it("delete item", async () => {
|
|
50
|
+
const token = await signupAndLogin();
|
|
35
51
|
const response1 = await request(app)
|
|
36
52
|
.post("/api/items")
|
|
37
53
|
.set("Accept", "application/json")
|
|
54
|
+
.set("Authorization", "Bearer " + token)
|
|
38
55
|
.send({ item: "hello world" });
|
|
39
|
-
|
|
40
56
|
const items = response1.body;
|
|
41
57
|
|
|
42
58
|
const response2 = await request(app)
|
|
43
59
|
.delete(`/api/items/${items[0].id}`)
|
|
44
|
-
.set("Accept", "application/json")
|
|
60
|
+
.set("Accept", "application/json")
|
|
61
|
+
.set("Authorization", "Bearer " + token);
|
|
45
62
|
|
|
46
|
-
expect(response2.headers["content-type"]).toMatch(/json/);
|
|
47
63
|
expect(response2.status).toEqual(200);
|
|
64
|
+
expect(response2.headers["content-type"]).toMatch(/json/);
|
|
48
65
|
expect(response2.body).toMatchObject([]);
|
|
49
66
|
});
|
|
50
67
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stanlemon/app-template",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.83",
|
|
4
4
|
"description": "A template for creating apps using the webdev package.",
|
|
5
5
|
"author": "Stan Lemon <stanlemon@users.noreply.github.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@stanlemon/server-with-auth": "*",
|
|
28
28
|
"@stanlemon/webdev": "*",
|
|
29
|
-
"react": "^19.
|
|
30
|
-
"react-cookie": "^
|
|
31
|
-
"react-dom": "^19.
|
|
29
|
+
"react": "^19.1.0",
|
|
30
|
+
"react-cookie": "^8.0.1",
|
|
31
|
+
"react-dom": "^19.1.0",
|
|
32
32
|
"wouter": "^3.6.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
package/src/App.test.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import App from "./App";
|
|
|
4
4
|
import { ItemData } from "./views";
|
|
5
5
|
import { SessionAware } from "./Session";
|
|
6
6
|
import { fetchApi } from "./helpers/fetchApi";
|
|
7
|
+
import { CookiesProvider } from "react-cookie";
|
|
7
8
|
|
|
8
9
|
jest.mock("./helpers/fetchApi");
|
|
9
10
|
|
|
@@ -14,9 +15,11 @@ describe("<App/>", () => {
|
|
|
14
15
|
|
|
15
16
|
it("logged out", async () => {
|
|
16
17
|
render(
|
|
17
|
-
<
|
|
18
|
-
<
|
|
19
|
-
|
|
18
|
+
<CookiesProvider>
|
|
19
|
+
<SessionAware initialized={true} token={null} user={null}>
|
|
20
|
+
<App />
|
|
21
|
+
</SessionAware>
|
|
22
|
+
</CookiesProvider>
|
|
20
23
|
);
|
|
21
24
|
|
|
22
25
|
expect(
|
|
@@ -37,17 +40,19 @@ describe("<App/>", () => {
|
|
|
37
40
|
mockedFetchApi.mockResolvedValue([]);
|
|
38
41
|
|
|
39
42
|
render(
|
|
40
|
-
<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
<CookiesProvider>
|
|
44
|
+
<SessionAware
|
|
45
|
+
initialized={true}
|
|
46
|
+
token="abcd"
|
|
47
|
+
user={{
|
|
48
|
+
username: "user",
|
|
49
|
+
name: "user",
|
|
50
|
+
email: "user@example.com",
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
<App />
|
|
54
|
+
</SessionAware>
|
|
55
|
+
</CookiesProvider>
|
|
51
56
|
);
|
|
52
57
|
|
|
53
58
|
// The header is present
|
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createRoot } from "react-dom/client";
|
|
2
2
|
import App from "./App";
|
|
3
3
|
import Session from "./Session";
|
|
4
|
+
import { CookiesProvider } from "react-cookie";
|
|
4
5
|
|
|
5
6
|
document.title = "App";
|
|
6
7
|
|
|
@@ -8,9 +9,11 @@ const root = createRoot(
|
|
|
8
9
|
document.body.appendChild(document.createElement("div"))
|
|
9
10
|
);
|
|
10
11
|
root.render(
|
|
11
|
-
<
|
|
12
|
-
<
|
|
13
|
-
|
|
12
|
+
<CookiesProvider>
|
|
13
|
+
<Session>
|
|
14
|
+
<App />
|
|
15
|
+
</Session>
|
|
16
|
+
</CookiesProvider>
|
|
14
17
|
);
|
|
15
18
|
|
|
16
19
|
const link = document.createElement("link");
|