mirror of
https://github.com/TautvydasDerzinskas/Thingport.git
synced 2026-10-21 14:12:25 -05:00
* feat: expand storage usage reporting with disk breakdown * feat: add providers admin view * feat(storage): add background reorganization and admin browser Adds background-driven storage reorganization for moving model files when the storage template changes, with an admin interface to preview changes, check impact, monitor progress, and browse the storage tree built from plate records rather than filesystem walks. * feat: new auth admin settings page + OIDC support * test: fix failing test
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { beforeAll, describe, expect, it } from "vitest";
|
|
import request from "supertest";
|
|
import { createApp } from "../src/app";
|
|
import { THUMBS } from "../src/config";
|
|
import { prisma } from "../src/db";
|
|
|
|
const app = createApp();
|
|
let token: string;
|
|
const thumb = path.join(THUMBS, `storage-usage-${Date.now()}.jpg`);
|
|
|
|
beforeAll(async () => {
|
|
const res = await request(app)
|
|
.post("/api/register")
|
|
.send({ displayName: "Storage", email: `storage-${Date.now()}@example.com`, password: "password123" });
|
|
await prisma.user.update({ where: { id: res.body.user.id }, data: { role: "ADMIN" } });
|
|
token = res.body.token;
|
|
// A known picture, measured before anything else asks (the measurement is kept for a few minutes).
|
|
fs.mkdirSync(THUMBS, { recursive: true });
|
|
fs.writeFileSync(thumb, Buffer.alloc(50_000));
|
|
return () => fs.rmSync(thumb, { force: true });
|
|
});
|
|
|
|
describe("storage usage", () => {
|
|
it("adds what's on disk, models' pictures and previews included, to what the models take", async () => {
|
|
const res = await request(app)
|
|
.get("/api/admin/storage")
|
|
.set({ Authorization: `Bearer ${token}` });
|
|
expect(res.status).toBe(200);
|
|
const usage = res.body as Record<string, number>;
|
|
expect(usage.picture_bytes).toBeGreaterThanOrEqual(50_000);
|
|
expect(usage.total_bytes).toBeGreaterThanOrEqual(usage.picture_bytes + usage.other_generated_bytes);
|
|
expect(usage.other_generated_bytes).toBeGreaterThanOrEqual(0);
|
|
});
|
|
});
|