Skip to content

Commit

Permalink
fix: maybe fix flakey test with kshook
Browse files Browse the repository at this point in the history
  • Loading branch information
zkrising committed Oct 16, 2023
1 parent 37516ff commit cd58e2e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
21 changes: 19 additions & 2 deletions server/src/server/router/ir/kshook/sv6c/router.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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
Expand Down Expand Up @@ -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) =>
Expand Down
9 changes: 3 additions & 6 deletions server/src/test-utils/fake-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ export async function CreateFakeAuthCookie(mockApi: supertest.SuperTest<supertes
return setCookieHeader;
}

// my local dev env hates this part because of pnpm
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function InsertFakeTokenWithAllPerms(token: string): () => any {
return async () => {
await db["api-tokens"].insert({
export function InsertFakeTokenWithAllPerms(token: string): () => Promise<any> {
return () =>
db["api-tokens"].insert({
userID: 1,
identifier: "Mock API Token",
permissions: ALL_PERMISSIONS,
token,
fromAPIClient: null,
});
};
}

0 comments on commit cd58e2e

Please sign in to comment.