web/src/lib had grown to 85 flat modules -- 42% of the web source, about
12,800 lines -- with one subdirectory (smime/) to its name. The tell was
that a naming prefix had taken over a directory's job: eight adminX.ts
files sat adjacent because alphabetical order put them there, not because
anything said they belonged together.
lib/admin/ adminAccess, adminDashboard, adminDirectory, adminDomains,
adminGroups, adminLists, adminRoles, adminTenants
lib/calendar/ appointment, availabilityWindow, eventDrag, ics, recurrence
Tests move with their modules into lib/admin/__tests__ and
lib/calendar/__tests__, which is what views/ already does. describeRules
stays in lib/__tests__: it checks that sieve's describeRule and
recurrence's agree, so it belongs to neither.
recurrence.ts joins the calendar group and archiveDate.ts does not, which
is the opposite of the first guess from the filenames. archiveDate picks
the Archive/2026/09 mailbox for a message -- mail, not calendar --
while recurrence reads JSCalendarRecurrenceRule. schedule.ts is scheduled
*send*, so it stays put too. birthdays.ts is left alone deliberately: it
is read off the contact cards and only rendered by the calendar, so it
belongs to whichever of the two you ask.
docs/ held no documentation. It held ten JPEGs and the two scripts that
capture them, while the actual documentation is a separate site in the
ihasmail.org repository -- so anyone opening docs/ expecting prose found
a headless-Chrome driver. The images are now screenshots/, and the two
capture scripts join the other .mjs tooling in scripts/, which is where a
generator belongs. Renaming docs/ to screenshots/ wholesale would have
produced screenshots/screenshots/inbox-dark.jpg.
No behavior changes: every import was already on the @/ alias, so this is
path rewrites and nothing else.
50 lines
2.5 KiB
TypeScript
50 lines
2.5 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { client } from "@/jmap/client";
|
|
import { countTenantMembers, drawableLogo, quotasPatch, setDomainTenant } from "@/lib/admin/adminTenants";
|
|
|
|
describe("a tenant's limits", () => {
|
|
it("change one pointer each, leaving the quotas ihasmail does not offer alone", () => {
|
|
const before = { maxAccounts: 25, maxDomains: 2, maxOauthClients: 7 };
|
|
expect(quotasPatch(before, { maxAccounts: 30, maxDomains: null, maxGroups: 5, maxRoles: null })).toEqual({
|
|
"quotas/maxAccounts": 30,
|
|
"quotas/maxDomains": null,
|
|
"quotas/maxGroups": 5,
|
|
});
|
|
expect(quotasPatch(before, { maxAccounts: 25 })).toEqual({});
|
|
});
|
|
});
|
|
|
|
describe("what a tenant holds", () => {
|
|
it("is counted with a memberTenantId filter per kind, users and groups apart", async () => {
|
|
const call = vi.spyOn(client, "call").mockImplementation(async (method, args) => {
|
|
const f = (args as { filter: Record<string, unknown> }).filter;
|
|
if (method === "x:Role/query") throw new Error("forbidden");
|
|
return { total: method === "x:Account/query" && f["@type"] === "Group" ? 2 : 1 };
|
|
});
|
|
expect(await countTenantMembers("t1")).toEqual({ accounts: 1, groups: 2, lists: 1, domains: 1, dkimKeys: 1 });
|
|
expect(call).toHaveBeenCalledWith("x:Account/query", { filter: { "@type": "User", memberTenantId: "t1" }, limit: 0, calculateTotal: true });
|
|
expect(call).toHaveBeenCalledWith("x:Domain/query", { filter: { memberTenantId: "t1" }, limit: 0, calculateTotal: true });
|
|
call.mockRestore();
|
|
});
|
|
|
|
it("moves a domain in and out by its memberTenantId", async () => {
|
|
const call = vi.spyOn(client, "call").mockResolvedValue({ updated: { d4: null } });
|
|
await setDomainTenant("d4", "t1");
|
|
expect(call).toHaveBeenLastCalledWith("x:Domain/set", { update: { d4: { memberTenantId: "t1" } } });
|
|
await setDomainTenant("d4", null);
|
|
expect(call).toHaveBeenLastCalledWith("x:Domain/set", { update: { d4: { memberTenantId: null } } });
|
|
call.mockRestore();
|
|
});
|
|
});
|
|
|
|
describe("a tenant's logo", () => {
|
|
it("is drawn only from https or an image data URL", () => {
|
|
expect(drawableLogo("https://example.com/logo.png")).toBe("https://example.com/logo.png");
|
|
expect(drawableLogo("data:image/png;base64,AAAA")).toBe("data:image/png;base64,AAAA");
|
|
expect(drawableLogo("http://example.com/logo.png")).toBeNull();
|
|
expect(drawableLogo("javascript:alert(1)")).toBeNull();
|
|
expect(drawableLogo("data:text/html;base64,AAAA")).toBeNull();
|
|
expect(drawableLogo(null)).toBeNull();
|
|
});
|
|
});
|