mirror of
https://github.com/outline/outline.git
synced 2026-01-07 19:49:58 -06:00
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { Event } from "@server/models";
|
|
import { sequelize } from "@server/storage/database";
|
|
import { buildDocument, buildUser } from "@server/test/factories";
|
|
import documentUpdater from "./documentUpdater";
|
|
|
|
describe("documentUpdater", () => {
|
|
const ip = "127.0.0.1";
|
|
|
|
it("should change lastModifiedById", async () => {
|
|
const user = await buildUser();
|
|
let document = await buildDocument({
|
|
teamId: user.teamId,
|
|
});
|
|
|
|
document = await sequelize.transaction(async (transaction) =>
|
|
documentUpdater({
|
|
text: "Changed",
|
|
document,
|
|
user,
|
|
ip,
|
|
transaction,
|
|
})
|
|
);
|
|
|
|
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 sequelize.transaction(async (transaction) =>
|
|
documentUpdater({
|
|
title: document.title,
|
|
document,
|
|
user,
|
|
ip,
|
|
transaction,
|
|
})
|
|
);
|
|
|
|
expect(document.lastModifiedById).not.toEqual(user.id);
|
|
});
|
|
});
|