* fix: rename to group_permissions * fix: delete null collectionId records before setting non null constraint * fix: use scope with collectionId not null * fix: update model with documentId * fix: rename to GroupPermission * fix: rename collection_users to user_permissions * fix: teamPermanentDeleter test * fix: use scope with collectionId not null * fix: update model with documentId * fix: rename to UserPermission * fix: create views upon table rename for zero downtime * fix: remove comments
34 lines
1004 B
TypeScript
34 lines
1004 B
TypeScript
import { CollectionPermission, UserRole } from "@shared/types";
|
|
import { UserPermission } from "@server/models";
|
|
import { buildUser, buildAdmin, buildCollection } from "@server/test/factories";
|
|
import userDemoter from "./userDemoter";
|
|
|
|
describe("userDemoter", () => {
|
|
const ip = "127.0.0.1";
|
|
|
|
it("should change role and associated collection permissions", async () => {
|
|
const admin = await buildAdmin();
|
|
const user = await buildUser({ teamId: admin.teamId });
|
|
const collection = await buildCollection({ teamId: admin.teamId });
|
|
|
|
const membership = await UserPermission.create({
|
|
createdById: admin.id,
|
|
userId: user.id,
|
|
collectionId: collection.id,
|
|
permission: CollectionPermission.ReadWrite,
|
|
});
|
|
|
|
await userDemoter({
|
|
user,
|
|
actorId: admin.id,
|
|
to: UserRole.Viewer,
|
|
ip,
|
|
});
|
|
|
|
expect(user.isViewer).toEqual(true);
|
|
|
|
await membership.reload();
|
|
expect(membership.permission).toEqual(CollectionPermission.Read);
|
|
});
|
|
});
|