Files
Thingport/backend/tests/publicUrl.test.ts
Tautvydas Derzinskas 9a2238691d feat: administration settings remake + OIDC support (#49)
* 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
2026-10-17 05:07:24 +02:00

60 lines
2.4 KiB
TypeScript

import request from "supertest";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { createApp } from "../src/app";
import { prisma } from "../src/db";
import { getPublicUrl, seedPublicUrl, setPublicUrl } from "../src/services/settingsService";
const app = createApp();
const stamp = Date.now();
let admin: string;
let previous: string;
beforeAll(async () => {
previous = await getPublicUrl();
const res = await request(app)
.post("/api/register")
.send({ displayName: "URL admin", email: `public-url-${stamp}@example.com`, password: "password123" });
admin = res.body.token;
await prisma.user.update({ where: { id: res.body.user.id }, data: { role: "ADMIN" } });
});
afterAll(async () => {
await setPublicUrl(previous || null);
});
describe("the public URL", () => {
it("is seeded from the environment once, then managed in the app", async () => {
await prisma.setting.deleteMany({ where: { key: "public_url" } });
await seedPublicUrl("https://from-env.example.com/");
expect(await getPublicUrl()).toBe("https://from-env.example.com");
// A later env value doesn't override what's stored.
await seedPublicUrl("https://changed-env.example.com");
expect(await getPublicUrl()).toBe("https://from-env.example.com");
const saved = await request(app)
.patch("/api/settings/public-url")
.set({ Authorization: `Bearer ${admin}` })
.send({ public_url: "https://thingport.example.com/" });
expect(saved.body).toEqual({ public_url: "https://thingport.example.com" });
const read = await request(app)
.get("/api/settings/public-url")
.set({ Authorization: `Bearer ${admin}` });
expect(read.body).toEqual({ public_url: "https://thingport.example.com" });
// A later env value doesn't override an admin's change either.
await seedPublicUrl("https://from-env.example.com");
expect(await getPublicUrl()).toBe("https://thingport.example.com");
});
it("refuses something that isn't a web address", async () => {
// Nor can it be emptied: emails and single sign-on need it.
for (const bad of ["", " ", null, "thingport.example.com", "ftp://x.example.com", "https://x.example.com/?a=1"]) {
const res = await request(app)
.patch("/api/settings/public-url")
.set({ Authorization: `Bearer ${admin}` })
.send({ public_url: bad });
expect(res.status).toBe(400);
}
});
});