mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-14 01:59:05 +03:00
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { RequireLoggedIn } from "./require-logged-in";
|
|
import expMiddlewareMock from "express-request-mock";
|
|
import t from "tap";
|
|
|
|
t.test("#RequireLoggedIn", (t) => {
|
|
t.test("Should reject users that are not logged in.", async (t) => {
|
|
const { res } = await expMiddlewareMock(RequireLoggedIn, {
|
|
session: {
|
|
tachi: null,
|
|
},
|
|
});
|
|
|
|
t.equal(res.statusCode, 401, "Should return 401.");
|
|
|
|
const json = res._getJSONData();
|
|
|
|
t.strictSame(json, {
|
|
success: false,
|
|
description: "You are not authorised to perform this action.",
|
|
});
|
|
});
|
|
|
|
t.test("Should allow users that are logged in.", async (t) => {
|
|
const { res } = await expMiddlewareMock(RequireLoggedIn, {
|
|
session: {
|
|
tachi: {
|
|
userID: 1,
|
|
},
|
|
},
|
|
});
|
|
|
|
t.equal(res.statusCode, 200, "Request should still be 200.");
|
|
});
|
|
|
|
t.end();
|
|
});
|