feat: add extensive test suite

This commit is contained in:
2026-08-30 11:33:53 +07:00 Unverified
parent 061cce00dc
commit 8359c7272e
131 changed files with 8717 additions and 2200 deletions
+48 -22
View File
@@ -2,30 +2,48 @@
import { revalidatePath } from "next/cache";
import { actionLog } from "@/lib/api";
import { adminCheck } from "@/lib/auth";
import { db } from "@/lib/db";
import { settings } from "@/lib/db/schema";
import { adminCheck } from "@/lib/auth";
import { sse } from "@/lib/db/sse-endpoints";
import { syncAmber as syncAmberRaw } from "@/util/sync";
import { getSettingsService, updateSettingService } from "./service";
export async function getSettongs() {
if (!(await adminCheck())) throw "Unauthorized";
const [
settangs = { enka: true, donatePromptpay: true, donateTruemoney: true },
] = await db.select().from(settings).limit(1);
return settangs;
return getSettingsService(
{ enka: true, donatePromptpay: true, donateTruemoney: true },
{
adminCheck,
read: async () =>
(
await db
.select({
enka: settings.enka,
donatePromptpay: settings.donatePromptpay,
donateTruemoney: settings.donateTruemoney,
})
.from(settings)
.limit(1)
)[0],
},
);
}
export async function toggleEnka(state: boolean) {
if (!(await adminCheck())) throw "Unauthorized";
await db
.insert(settings)
.values({ enka: state })
.onConflictDoUpdate({ target: settings.id, set: { enka: state } });
await actionLog("Changed a settings", { enka: state });
revalidatePath("/admin/settings");
revalidatePath("/artifact");
return updateSettingService(state, {
adminCheck,
persist: async (value) => {
await db
.insert(settings)
.values({ enka: value })
.onConflictDoUpdate({ target: settings.id, set: { enka: value } });
},
afterPersist: async (value) => {
await actionLog("Changed a settings", { enka: value });
revalidatePath("/admin/settings");
revalidatePath("/artifact");
},
});
}
export async function syncAmber() {
@@ -48,11 +66,19 @@ export async function toggleDonatePaymentMethod(
method: "donatePromptpay" | "donateTruemoney",
state: boolean,
) {
if (!(await adminCheck())) throw "Unauthorized";
await db
.insert(settings)
.values({ [method]: state })
.onConflictDoUpdate({ target: settings.id, set: { [method]: state } });
await actionLog("Changed a settings", { [method]: state });
return updateSettingService(state, {
adminCheck,
persist: async (value) => {
await db
.insert(settings)
.values({ [method]: value })
.onConflictDoUpdate({
target: settings.id,
set: { [method]: value },
});
},
afterPersist: async (value) => {
await actionLog("Changed a settings", { [method]: value });
},
});
}