mirror of
https://github.com/outline/outline.git
synced 2026-11-25 23:24:06 +03:00
* chore: Rename APIContext to Context and flatten its fields Auth and transaction now live directly on the context instead of in ctx.state and a nested ctx.context, and model helpers read them directly. APIContext remains as a deprecated alias. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * chore: Remove deprecated APIContext alias Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * fix: Read auth from context in OAuth provider callbacks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * chore: Add withUser and withTransaction context helpers Replaces manual createContext rebuilds that copy fields from an existing context. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * chore: Remove arbitrary property access from Koa context types AppContext and Context no longer inherit the any index signature from Koa's DefaultContext, custom fields are declared explicitly, and importing Koa's loose Context type is disallowed by lint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf --------- Co-authored-by: Claude <noreply@anthropic.com>
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import { createContext, toHookContext } from "@server/context";
|
|
import {
|
|
buildCollection,
|
|
buildDocument,
|
|
buildTeam,
|
|
buildUser,
|
|
} from "@server/test/factories";
|
|
|
|
describe("ParanoidModel", () => {
|
|
describe("deletedById", () => {
|
|
it("should record the acting user on destroy", async () => {
|
|
const user = await buildUser();
|
|
const document = await buildDocument({ teamId: user.teamId });
|
|
|
|
await document.destroy(toHookContext(createContext({ user })));
|
|
await document.reload({ paranoid: false });
|
|
|
|
expect(document.deletedAt).toBeTruthy();
|
|
expect(document.deletedById).toEqual(user.id);
|
|
});
|
|
|
|
it("should clear the recorded user on restore", async () => {
|
|
const user = await buildUser();
|
|
const document = await buildDocument({ teamId: user.teamId });
|
|
|
|
await document.destroy(toHookContext(createContext({ user })));
|
|
await document.restore();
|
|
await document.reload();
|
|
|
|
expect(document.deletedAt).toBeNull();
|
|
expect(document.deletedById).toBeNull();
|
|
});
|
|
|
|
it("should record nothing when the context is unauthenticated", async () => {
|
|
const document = await buildDocument();
|
|
|
|
await document.destroy();
|
|
await document.reload({ paranoid: false });
|
|
|
|
expect(document.deletedAt).toBeTruthy();
|
|
expect(document.deletedById).toBeNull();
|
|
});
|
|
|
|
it("should ignore models without the column", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
// A team must keep at least one collection, so build a second to delete.
|
|
await buildCollection({ teamId: team.id, userId: user.id });
|
|
const collection = await buildCollection({
|
|
teamId: team.id,
|
|
userId: user.id,
|
|
});
|
|
|
|
await collection.destroy(toHookContext(createContext({ user })));
|
|
|
|
expect(collection.deletedAt).toBeTruthy();
|
|
});
|
|
});
|
|
});
|