This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously. closes #1282
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { CollectionGroup, GroupUser } from "@server/models";
|
|
import { buildUser, buildGroup, buildCollection } from "@server/test/factories";
|
|
import { flushdb } from "@server/test/support";
|
|
|
|
beforeEach(() => flushdb());
|
|
beforeEach(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.addUser(user1, {
|
|
through: {
|
|
createdById,
|
|
},
|
|
});
|
|
await group.addUser(user2, {
|
|
through: {
|
|
createdById,
|
|
},
|
|
});
|
|
await collection1.addGroup(group, {
|
|
through: {
|
|
createdById,
|
|
},
|
|
});
|
|
await collection2.addGroup(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);
|
|
});
|
|
});
|