-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test new session stubbing fix with dedicated route
- Loading branch information
Showing
5 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { RequestHandler } from "express"; | ||
|
||
export const testSessionMethods: RequestHandler = (req, res) => { | ||
const hasRegenerate = typeof req.session?.regenerate === "function"; | ||
const hasSave = typeof req.session?.save === "function"; | ||
res.status(200).json({ hasRegenerate, hasSave }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
openapi: 3.1.0 | ||
info: | ||
title: Plan✕ API | ||
version: 0.1.0 | ||
tags: | ||
- name: test | ||
description: Requests for testing purposes | ||
paths: | ||
/test-session: | ||
get: | ||
summary: Test req.session object | ||
description: Confirms session has necessary dummy methods registered | ||
tags: ["test"] | ||
responses: | ||
"200": | ||
description: OK | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
hasRegenerate: | ||
type: boolean | ||
hasSave: | ||
type: boolean | ||
example: | ||
hasRegenerate: true | ||
hasSave: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import supertest from "supertest"; | ||
import app from "../../server"; | ||
|
||
describe("Session setup", () => { | ||
test("adds dummy methods to req.session to avoid passport/cookie-session incompatibility issue", async () => { | ||
await supertest(app) | ||
.get("/test-session") | ||
.expect(200) | ||
.then((res) => { | ||
expect(res.body.hasRegenerate).toBe(true); | ||
expect(res.body.hasSave).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Router } from "express"; | ||
import { testSessionMethods } from "./controller"; | ||
|
||
const router = Router(); | ||
|
||
// in order to test the session setup, we need a dedicated test route | ||
router.get("/test-session", testSessionMethods); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters