Skip to content

Commit 5ff81bb

Browse files
fix: add missing newline at end of package.json and standardize quotes in pnpm-workspace.yaml
refactor: update formatting in sessionManager.test.ts for consistency
1 parent 999b35c commit 5ff81bb

4 files changed

Lines changed: 45 additions & 52 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@
9090
"express-session": "^1.18.1",
9191
"qs": "^6.14.0"
9292
}
93-
}
93+
}

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
overrides:
2-
'@kinde/js-utils': link:../js-utils
2+
"@kinde/js-utils": link:../js-utils

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export { jwtVerify };
2121
*/
2222
export const setupKinde = <G extends GrantType>(
2323
config: SetupConfig<G>,
24-
app: Express
24+
app: Express,
2525
) => {
2626
// setting up expressSession layer first for Kinde
2727
setupKindeSession(app);

src/setup/sessionManager.test.ts

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,96 @@
1-
import {
2-
describe,
3-
it,
4-
expect,
5-
beforeEach,
6-
} from 'vitest';
7-
import express, {
8-
type Express,
9-
} from 'express';
10-
import request from 'supertest';
11-
import session from 'express-session';
12-
import { setupKindeSession } from './sessionManager.js';
1+
import { describe, it, expect, beforeEach } from "vitest";
2+
import express, { type Express } from "express";
3+
import request from "supertest";
4+
import session from "express-session";
5+
import { setupKindeSession } from "./sessionManager.js";
136

14-
describe('sessionManager', () => {
7+
describe("sessionManager", () => {
158
let app: Express;
169

1710
beforeEach(() => {
1811
app = express();
1912
app.use(express.json());
2013
});
2114

22-
describe('setupKindeSession()', () => {
23-
it('should add session middleware if it has not been added', () => {
15+
describe("setupKindeSession()", () => {
16+
it("should add session middleware if it has not been added", () => {
2417
setupKindeSession(app);
2518
const sessionMiddleware = app._router.stack.find(
26-
(layer) => layer.name === 'session'
19+
(layer) => layer.name === "session",
2720
);
2821
expect(sessionMiddleware).toBeDefined();
2922
});
3023

31-
it('should not add session middleware if it has already been added', () => {
24+
it("should not add session middleware if it has already been added", () => {
3225
app.use(
3326
session({
3427
secret:
3528
process.env.TEST_SESSION_SECRET || "test-secret-" + Date.now(),
3629
resave: false,
3730
saveUninitialized: true,
38-
})
31+
}),
3932
);
4033
const sessionMiddlewareCount = app._router.stack.filter(
41-
(layer) => layer.name === 'session'
34+
(layer) => layer.name === "session",
4235
).length;
4336
expect(sessionMiddlewareCount).toBe(1);
4437
setupKindeSession(app);
4538
const sessionMiddlewareCountAfter = app._router.stack.filter(
46-
(layer) => layer.name === 'session'
39+
(layer) => layer.name === "session",
4740
).length;
4841
expect(sessionMiddlewareCountAfter).toBe(1);
4942
});
5043

51-
it('should add getSessionManager middleware', () => {
44+
it("should add getSessionManager middleware", () => {
5245
const initialStackLength = app._router.stack.length;
5346
setupKindeSession(app);
5447
const finalStackLength = app._router.stack.length;
5548
expect(finalStackLength).toBeGreaterThan(initialStackLength);
5649
});
5750
});
5851

59-
describe('ExpressSessionManager functionality', () => {
52+
describe("ExpressSessionManager functionality", () => {
6053
beforeEach(() => {
6154
setupKindeSession(app);
62-
app.get('/session-functions', (req, res) => {
55+
app.get("/session-functions", (req, res) => {
6356
res.json({
64-
setSessionItem: typeof req.setSessionItem === 'function',
65-
getSessionItem: typeof req.getSessionItem === 'function',
66-
removeSessionItem: typeof req.removeSessionItem === 'function',
67-
destroySession: typeof req.destroySession === 'function',
57+
setSessionItem: typeof req.setSessionItem === "function",
58+
getSessionItem: typeof req.getSessionItem === "function",
59+
removeSessionItem: typeof req.removeSessionItem === "function",
60+
destroySession: typeof req.destroySession === "function",
6861
});
6962
});
7063

71-
app.post('/set-item', async (req, res) => {
64+
app.post("/set-item", async (req, res) => {
7265
const { key, value } = req.body;
7366
await req.setSessionItem(key, value);
7467
res.sendStatus(200);
7568
});
7669

77-
app.get('/get-item', async (req, res) => {
70+
app.get("/get-item", async (req, res) => {
7871
const { key } = req.query;
7972
const value = await req.getSessionItem(key as string);
8073
res.json({ value });
8174
});
8275

83-
app.post('/remove-item', async (req, res) => {
76+
app.post("/remove-item", async (req, res) => {
8477
const { key } = req.body;
8578
await req.removeSessionItem(key);
8679
res.sendStatus(200);
8780
});
8881

89-
app.post('/destroy', async (req, res) => {
82+
app.post("/destroy", async (req, res) => {
9083
try {
9184
await req.destroySession();
9285
res.sendStatus(200);
9386
} catch {
94-
res.status(500).send('Error destroying session');
87+
res.status(500).send("Error destroying session");
9588
}
9689
});
9790
});
9891

99-
it('adds ExpressSessionManager methods to the request object', async () => {
100-
const res = await request(app).get('/session-functions');
92+
it("adds ExpressSessionManager methods to the request object", async () => {
93+
const res = await request(app).get("/session-functions");
10194
expect(res.status).toBe(200);
10295
expect(res.body).toEqual({
10396
setSessionItem: true,
@@ -107,32 +100,32 @@ describe('sessionManager', () => {
107100
});
108101
});
109102

110-
it('sets and gets a session item via ExpressSessionManager', async () => {
103+
it("sets and gets a session item via ExpressSessionManager", async () => {
111104
const agent = request.agent(app);
112105
await agent
113-
.post('/set-item')
114-
.send({ key: 'testKey', value: 'testValue' });
115-
const res = await agent.get('/get-item').query({ key: 'testKey' });
116-
expect(res.body.value).toBe('testValue');
106+
.post("/set-item")
107+
.send({ key: "testKey", value: "testValue" });
108+
const res = await agent.get("/get-item").query({ key: "testKey" });
109+
expect(res.body.value).toBe("testValue");
117110
});
118111

119-
it('removes a session item via ExpressSessionManager', async () => {
112+
it("removes a session item via ExpressSessionManager", async () => {
120113
const agent = request.agent(app);
121114
await agent
122-
.post('/set-item')
123-
.send({ key: 'testKey', value: 'testValue' });
124-
await agent.post('/remove-item').send({ key: 'testKey' });
125-
const res = await agent.get('/get-item').query({ key: 'testKey' });
115+
.post("/set-item")
116+
.send({ key: "testKey", value: "testValue" });
117+
await agent.post("/remove-item").send({ key: "testKey" });
118+
const res = await agent.get("/get-item").query({ key: "testKey" });
126119
expect(res.body.value).toBe(null);
127120
});
128121

129-
it('destroys the session via ExpressSessionManager', async () => {
122+
it("destroys the session via ExpressSessionManager", async () => {
130123
const agent = request.agent(app);
131124
await agent
132-
.post('/set-item')
133-
.send({ key: 'testKey', value: 'testValue' });
134-
await agent.post('/destroy');
135-
const res = await agent.get('/get-item').query({ key: 'testKey' });
125+
.post("/set-item")
126+
.send({ key: "testKey", value: "testValue" });
127+
await agent.post("/destroy");
128+
const res = await agent.get("/get-item").query({ key: "testKey" });
136129
expect(res.body.value).toBe(null);
137130
});
138131
});

0 commit comments

Comments
 (0)