Skip to content

Update dependency react-cookie to v8 #271

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

Merged
merged 2 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 2 deletions apps/template/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stanlemon/app-template",
"version": "0.3.80",
"version": "0.3.82",
"description": "A template for creating apps using the webdev package.",
"author": "Stan Lemon <stanlemon@users.noreply.github.com>",
"license": "MIT",
Expand All @@ -27,7 +27,7 @@
"@stanlemon/server-with-auth": "*",
"@stanlemon/webdev": "*",
"react": "^19.0.0",
"react-cookie": "^7.2.2",
"react-cookie": "^8.0.1",
"react-dom": "^19.0.0",
"wouter": "^3.6.0"
},
Expand Down
33 changes: 19 additions & 14 deletions apps/template/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import App from "./App";
import { ItemData } from "./views";
import { SessionAware } from "./Session";
import { fetchApi } from "./helpers/fetchApi";
import { CookiesProvider } from "react-cookie";

jest.mock("./helpers/fetchApi");

Expand All @@ -14,9 +15,11 @@ describe("<App/>", () => {

it("logged out", async () => {
render(
<SessionAware initialized={true} token={null} user={null}>
<App />
</SessionAware>
<CookiesProvider>
<SessionAware initialized={true} token={null} user={null}>
<App />
</SessionAware>
</CookiesProvider>
);

expect(
Expand All @@ -37,17 +40,19 @@ describe("<App/>", () => {
mockedFetchApi.mockResolvedValue([]);

render(
<SessionAware
initialized={true}
token="abcd"
user={{
username: "user",
name: "user",
email: "user@example.com",
}}
>
<App />
</SessionAware>
<CookiesProvider>
<SessionAware
initialized={true}
token="abcd"
user={{
username: "user",
name: "user",
email: "user@example.com",
}}
>
<App />
</SessionAware>
</CookiesProvider>
);

// The header is present
Expand Down
9 changes: 6 additions & 3 deletions apps/template/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { createRoot } from "react-dom/client";
import App from "./App";
import Session from "./Session";
import { CookiesProvider } from "react-cookie";

document.title = "App";

const root = createRoot(
document.body.appendChild(document.createElement("div"))
);
root.render(
<Session>
<App />
</Session>
<CookiesProvider>
<Session>
<App />
</Session>
</CookiesProvider>
);

const link = document.createElement("link");
Expand Down
69 changes: 51 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stanlemon/server",
"version": "0.3.45",
"version": "0.3.46",
"description": "A basic express web server setup.",
"author": "Stan Lemon <stanlemon@users.noreply.github.com>",
"license": "MIT",
Expand Down
97 changes: 97 additions & 0 deletions packages/server/src/asyncJsonHandler.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import asyncJsonHandler from "./asyncJsonHandler";

describe("asyncHandler()", () => {
it("handles fn response", async () => {
const body = {
hello: "World",
};
const req = jest.fn();
const res = jest.fn();
res.status = jest.fn().mockReturnValue({ json: jest.fn() });
const next = jest.fn();

const controller = async (req, res, next) => {
return Promise.resolve(body);
};

await asyncJsonHandler(controller)(req, res, next);

expect(res.status.mock.calls[0][0]).toBe(200);
expect(res.status().json.mock.calls[0][0]).toEqual(body);
});

it("handles fn 400", async () => {
const req = jest.fn();
const res = jest.fn();
res.status = jest.fn().mockReturnValue({ json: jest.fn() });
const next = jest.fn();

const controller = async (req, res, next) => {
throw new Error("Bad Request");
};

await asyncJsonHandler(controller)(req, res, next);

expect(res.status.mock.calls[0][0]).toBe(400);
});

it("handles fn 403", async () => {
const req = jest.fn();
const res = jest.fn();
res.status = jest.fn().mockReturnValue({ json: jest.fn() });
const next = jest.fn();

const controller = async (req, res, next) => {
throw new Error("Not Authorized");
};

await asyncJsonHandler(controller)(req, res, next);

expect(res.status.mock.calls[0][0]).toBe(403);
});

it("handles fn 404", async () => {
const req = jest.fn();
const res = jest.fn();
res.status = jest.fn().mockReturnValue({ json: jest.fn() });
const next = jest.fn();

const controller = async (req, res, next) => {
throw new Error("Not Found");
};

await asyncJsonHandler(controller)(req, res, next);

expect(res.status.mock.calls[0][0]).toBe(404);
});

it("handles fn 409", async () => {
const req = jest.fn();
const res = jest.fn();
res.status = jest.fn().mockReturnValue({ json: jest.fn() });
const next = jest.fn();

const controller = async (req, res, next) => {
throw new Error("Already Exists");
};

await asyncJsonHandler(controller)(req, res, next);

expect(res.status.mock.calls[0][0]).toBe(409);
});

it("handles fn 500", async () => {
const req = jest.fn();
const res = jest.fn();
res.status = jest.fn().mockReturnValue({ json: jest.fn() });
const next = jest.fn();

const controller = async (req, res, next) => {
throw new Error("Who knows!");
};

await asyncJsonHandler(controller)(req, res, next);

expect(res.status.mock.calls[0][0]).toBe(500);
});
});
4 changes: 3 additions & 1 deletion packages/server/src/schemaHandler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ValidationError } from "joi";
import Joi from "joi";
import { asyncJsonHandler } from "./asyncJsonHandler.js";

const { ValidationError } = Joi;

/**
*
* @param {Joi.Schema} schema
Expand Down
Loading