Files
outline/server/commands/documentUpdater.test.ts
Apoorv Mishra 0c51bfb899 perf: reduce memory usage upon running server tests (#3949)
* perf: reduce memory usage upon running server tests

* perf: plug leaks in server/routes

* perf: plug leaks in server/scripts

* perf: plug leaks in server/policies

* perf: plug leaks in server/models

* perf: plug leaks in server/middlewares

* perf: plug leaks in server/commands

* fix: missing await on db.flush

* perf: plug leaks in server/queues

* chore: remove unused legacy funcs

* fix: await on db.flush

* perf: await on GC to run in between tests

* fix: remove db refs

* fix: revert embeds

* perf: plug leaks in shared/i18n
2022-08-11 21:39:17 +05:30

59 lines
1.5 KiB
TypeScript

import { sequelize } from "@server/database/sequelize";
import { Event } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { getTestDatabase } from "@server/test/support";
import documentUpdater from "./documentUpdater";
const db = getTestDatabase();
afterAll(db.disconnect);
beforeEach(db.flush);
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.findOne();
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,
})
);
const event = await Event.findOne();
expect(document.lastModifiedById).not.toEqual(user.id);
expect(event).toEqual(null);
});
});