test: add vitest

* feature(root): add vitest and some basic tests

* fix(test): after rebase + added referrars test and more sites

* fix(test): test broken after rebase

* fix(test): provide db url to make prisma happy

* fix tests
This commit is contained in:
Carl-Gerhard Lindesvärd
2025-06-06 19:14:18 +02:00
committed by GitHub
parent 09c83ddeb4
commit 5445d6309e
23 changed files with 1131 additions and 3133 deletions

View File

@@ -1,40 +0,0 @@
import type { Queue } from 'bullmq';
export async function findJobByPrefix<T>(
queue: Queue<T, any, string>,
keys: string[],
matcher: string,
) {
const getTime = (val?: string) => {
if (!val) return null;
const match = val.match(/:(\d+)$/);
return match?.[1] ? Number.parseInt(match[1], 10) : null;
};
const filtered = keys
.filter((key) => key.includes(matcher))
.filter((key) => getTime(key));
filtered.sort((a, b) => {
const aTime = getTime(a);
const bTime = getTime(b);
if (aTime === null) return 1;
if (bTime === null) return -1;
return aTime - bTime;
});
async function getJob(index: number) {
if (index >= filtered.length) return null;
const key = filtered[index]?.replace(/^bull:(\w+):/, '');
// return new Promise((resolve) => )
if (key) {
const job = await queue.getJob(key);
if ((await job?.getState()) === 'delayed') {
return job;
}
}
return getJob(index + 1);
}
return getJob(0);
}