mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-02 03:48:14 +03:00
kai tests
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
import t from "tap";
|
||||
import expMiddlewareMock from "express-request-mock";
|
||||
import { ValidateKaiType } from "./middleware";
|
||||
|
||||
t.test("#ValidateKaiType", (t) => {
|
||||
const k = async (k: string) => {
|
||||
const { res } = await expMiddlewareMock(ValidateKaiType, { params: { kaiType: k } });
|
||||
|
||||
return res.statusCode;
|
||||
};
|
||||
|
||||
t.test("Should allow flo, eag or min, case insensitively.", async (t) => {
|
||||
t.equal(await k("flo"), 200);
|
||||
t.equal(await k("eag"), 200);
|
||||
t.equal(await k("min"), 200);
|
||||
t.equal(await k("FLO"), 200);
|
||||
t.equal(await k("EAG"), 200);
|
||||
t.equal(await k("MIN"), 200);
|
||||
t.equal(await k("FlO"), 200);
|
||||
t.equal(await k("EaG"), 200);
|
||||
t.equal(await k("MiN"), 200);
|
||||
t.equal(await k("nonsense"), 400);
|
||||
t.equal(await k("bad"), 400);
|
||||
t.equal(await k(""), 400);
|
||||
t.equal(await k("FLO2"), 400);
|
||||
t.equal(await k("2FLO"), 400);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
export const ValidateKaiType: RequestHandler = (req, res, next) => {
|
||||
if (!["min", "flo", "eag"].includes(req.params.kaiType)) {
|
||||
if (!["min", "flo", "eag"].includes(req.params.kaiType.toLowerCase())) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
description: `Invalid kaiType - Expected min, flo or eag.`,
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
import db from "external/mongo/db";
|
||||
import t from "tap";
|
||||
import { CloseAllConnections } from "test-utils/close-connections";
|
||||
import { CreateFakeAuthCookie } from "test-utils/fake-auth";
|
||||
import mockApi from "test-utils/mock-api";
|
||||
import ResetDBState from "test-utils/resets";
|
||||
|
||||
t.test("GET /api/v1/users/:userID/integrations/kai/:kaiType", async (t) => {
|
||||
t.beforeEach(ResetDBState);
|
||||
|
||||
const cookie = await CreateFakeAuthCookie(mockApi);
|
||||
|
||||
t.test("Should return false if unauthed with this kaiType", async (t) => {
|
||||
const res = await mockApi.get("/api/v1/users/1/integrations/kai/flo").set("Cookie", cookie);
|
||||
|
||||
t.equal(res.statusCode, 200);
|
||||
t.equal(res.body.body.authStatus, false);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should return true if authed with this kaiType", async (t) => {
|
||||
await db["kai-auth-tokens"].insert({
|
||||
refreshToken: "refresh",
|
||||
service: "FLO",
|
||||
token: "bar",
|
||||
userID: 1,
|
||||
});
|
||||
|
||||
const res = await mockApi.get("/api/v1/users/1/integrations/kai/flo").set("Cookie", cookie);
|
||||
|
||||
t.equal(res.statusCode, 200);
|
||||
t.equal(res.body.body.authStatus, true);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test("Should return the auth status of this user specifically.", async (t) => {
|
||||
await db["kai-auth-tokens"].insert([
|
||||
{
|
||||
refreshToken: "refresh",
|
||||
service: "EAG",
|
||||
token: "bar",
|
||||
userID: 1,
|
||||
},
|
||||
{
|
||||
refreshToken: "refresh",
|
||||
service: "FLO",
|
||||
token: "baz",
|
||||
userID: 2,
|
||||
},
|
||||
]);
|
||||
|
||||
const res = await mockApi.get("/api/v1/users/1/integrations/kai/flo").set("Cookie", cookie);
|
||||
|
||||
t.equal(res.statusCode, 200);
|
||||
t.equal(res.body.body.authStatus, false);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
// test is currently undoable due to issues with mocking out real Fetch calls.
|
||||
t.todo("PATCH /api/v1/userse/:userID/integrations/kai/:kaiType/oauth2callback");
|
||||
|
||||
t.teardown(CloseAllConnections);
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
Reference in New Issue
Block a user