From cd58e2e150b60ab771fc9eb1a0ea83d9b18e678a Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:57:26 +0100 Subject: [PATCH] fix: maybe fix flakey test with kshook --- .../router/ir/kshook/sv6c/router.test.ts | 21 +++++++++++++++++-- server/src/test-utils/fake-auth.ts | 9 +++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/server/src/server/router/ir/kshook/sv6c/router.test.ts b/server/src/server/router/ir/kshook/sv6c/router.test.ts index 335d8c745..904957a4f 100644 --- a/server/src/server/router/ir/kshook/sv6c/router.test.ts +++ b/server/src/server/router/ir/kshook/sv6c/router.test.ts @@ -1,5 +1,6 @@ import deepmerge from "deepmerge"; import db from "external/mongo/db"; +import { ALL_PERMISSIONS } from "tachi-common"; import t from "tap"; import { InsertFakeTokenWithAllPerms } from "test-utils/fake-auth"; import mockApi from "test-utils/mock-api"; @@ -8,7 +9,15 @@ import { TestingKsHookSV6CScore, TestingKsHookSV6CStaticScore } from "test-utils t.test("POST /ir/kshook/sv6c/score/save", (t) => { t.beforeEach(ResetDBState); - t.beforeEach(InsertFakeTokenWithAllPerms("mock_token")); + t.beforeEach(() => + db["api-tokens"].insert({ + userID: 1, + identifier: "Mock API Token", + permissions: ALL_PERMISSIONS, + token: "mock_token", + fromAPIClient: null, + }) + ); t.test("Should import a valid score to the database.", async (t) => { const res = await mockApi @@ -107,7 +116,15 @@ t.test("POST /ir/kshook/sv6c/score/save", (t) => { t.test("POST /ir/kshook/sv6c/score/export", (t) => { t.beforeEach(ResetDBState); - t.beforeEach(InsertFakeTokenWithAllPerms("mock_token")); + t.beforeEach(() => + db["api-tokens"].insert({ + userID: 1, + identifier: "Mock API Token", + permissions: ALL_PERMISSIONS, + token: "mock_token", + fromAPIClient: null, + }) + ); // eslint-disable-next-line @typescript-eslint/ban-types const validSubmit = (data: object) => diff --git a/server/src/test-utils/fake-auth.ts b/server/src/test-utils/fake-auth.ts index 8400c9114..ea6dca8cf 100644 --- a/server/src/test-utils/fake-auth.ts +++ b/server/src/test-utils/fake-auth.ts @@ -34,16 +34,13 @@ export async function CreateFakeAuthCookie(mockApi: supertest.SuperTest any { - return async () => { - await db["api-tokens"].insert({ +export function InsertFakeTokenWithAllPerms(token: string): () => Promise { + return () => + db["api-tokens"].insert({ userID: 1, identifier: "Mock API Token", permissions: ALL_PERMISSIONS, token, fromAPIClient: null, }); - }; }