* 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
44 lines
1005 B
TypeScript
44 lines
1005 B
TypeScript
import { Star, Event } from "@server/models";
|
|
import { buildDocument, buildUser } from "@server/test/factories";
|
|
import { getTestDatabase } from "@server/test/support";
|
|
import starDestroyer from "./starDestroyer";
|
|
|
|
const db = getTestDatabase();
|
|
|
|
afterAll(db.disconnect);
|
|
|
|
beforeEach(db.flush);
|
|
|
|
describe("starDestroyer", () => {
|
|
const ip = "127.0.0.1";
|
|
|
|
it("should destroy existing star", async () => {
|
|
const user = await buildUser();
|
|
const document = await buildDocument({
|
|
userId: user.id,
|
|
teamId: user.teamId,
|
|
});
|
|
|
|
const star = await Star.create({
|
|
teamId: document.teamId,
|
|
documentId: document.id,
|
|
userId: user.id,
|
|
createdById: user.id,
|
|
index: "P",
|
|
});
|
|
|
|
await starDestroyer({
|
|
star,
|
|
user,
|
|
ip,
|
|
});
|
|
|
|
const count = await Star.count();
|
|
expect(count).toEqual(0);
|
|
|
|
const event = await Event.findOne();
|
|
expect(event!.name).toEqual("stars.delete");
|
|
expect(event!.modelId).toEqual(star.id);
|
|
});
|
|
});
|