mirror of
https://github.com/outline/outline.git
synced 2026-05-02 07:29:41 -05:00
142985c6d7
* documents.restore, documents.unarchive * documents.templatize * documents.archive * documents.unpublish * documents.create, documents.update * documents.title_change event * documents.move * documents.delete * tsc, tests * tsc * Copilot feedback --------- Co-authored-by: Tom Moor <tom@getoutline.com>
74 lines
1.8 KiB
TypeScript
74 lines
1.8 KiB
TypeScript
import { Event } from "@server/models";
|
|
import { buildDocument, buildUser } from "@server/test/factories";
|
|
import { withAPIContext } from "@server/test/support";
|
|
import documentUpdater from "./documentUpdater";
|
|
|
|
describe("documentUpdater", () => {
|
|
it("should change lastModifiedById", async () => {
|
|
const user = await buildUser();
|
|
let document = await buildDocument({
|
|
teamId: user.teamId,
|
|
});
|
|
|
|
document = await withAPIContext(user, (ctx) =>
|
|
documentUpdater(ctx, {
|
|
text: "Changed",
|
|
document,
|
|
})
|
|
);
|
|
|
|
const event = await Event.findLatest({
|
|
teamId: user.teamId,
|
|
});
|
|
expect(document.lastModifiedById).toEqual(user.id);
|
|
expect(event!.name).toEqual("documents.update");
|
|
expect(event!.documentId).toEqual(document.id);
|
|
});
|
|
|
|
it("should not change lastModifiedById or generate event if nothing changed", async () => {
|
|
const user = await buildUser();
|
|
let document = await buildDocument({
|
|
teamId: user.teamId,
|
|
});
|
|
|
|
document = await withAPIContext(user, (ctx) =>
|
|
documentUpdater(ctx, {
|
|
title: document.title,
|
|
document,
|
|
})
|
|
);
|
|
|
|
expect(document.lastModifiedById).not.toEqual(user.id);
|
|
});
|
|
|
|
it("should update document content when changing text", async () => {
|
|
const user = await buildUser();
|
|
let document = await buildDocument({
|
|
teamId: user.teamId,
|
|
});
|
|
|
|
document = await withAPIContext(user, (ctx) =>
|
|
documentUpdater(ctx, {
|
|
text: "Changed",
|
|
document,
|
|
})
|
|
);
|
|
|
|
expect(document.text).toEqual("Changed");
|
|
expect(document.content).toEqual({
|
|
type: "doc",
|
|
content: [
|
|
{
|
|
type: "paragraph",
|
|
content: [
|
|
{
|
|
type: "text",
|
|
text: "Changed",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
});
|
|
});
|