Files
outline/server/models/Group.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

65 lines
1.6 KiB
TypeScript

import { buildUser, buildGroup, buildCollection } from "@server/test/factories";
import { getTestDatabase } from "@server/test/support";
import CollectionGroup from "./CollectionGroup";
import GroupUser from "./GroupUser";
const db = getTestDatabase();
afterAll(db.disconnect);
beforeEach(async () => {
await db.flush();
jest.resetAllMocks();
});
describe("afterDestroy hook", () => {
test("should destroy associated group and collection join relations", async () => {
const group = await buildGroup();
const teamId = group.teamId;
const user1 = await buildUser({
teamId,
});
const user2 = await buildUser({
teamId,
});
const collection1 = await buildCollection({
permission: null,
teamId,
});
const collection2 = await buildCollection({
permission: null,
teamId,
});
const createdById = user1.id;
await group.$add("user", user1, {
through: {
createdById,
},
});
await group.$add("user", user2, {
through: {
createdById,
},
});
await collection1.$add("group", group, {
through: {
createdById,
},
});
await collection2.$add("group", group, {
through: {
createdById,
},
});
let collectionGroupCount = await CollectionGroup.count();
let groupUserCount = await GroupUser.count();
expect(collectionGroupCount).toBe(2);
expect(groupUserCount).toBe(2);
await group.destroy();
collectionGroupCount = await CollectionGroup.count();
groupUserCount = await GroupUser.count();
expect(collectionGroupCount).toBe(0);
expect(groupUserCount).toBe(0);
});
});