fix: withCollection scopes on UserPermission, GroupPermission
This commit is contained in:
29
server/models/GroupPermission.test.ts
Normal file
29
server/models/GroupPermission.test.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { buildCollection, buildGroup, buildUser } from "@server/test/factories";
|
||||||
|
import GroupPermission from "./GroupPermission";
|
||||||
|
|
||||||
|
describe("GroupPermission", () => {
|
||||||
|
describe("withCollection scope", () => {
|
||||||
|
it("should return the collection", async () => {
|
||||||
|
const collection = await buildCollection();
|
||||||
|
const group = await buildGroup();
|
||||||
|
const user = await buildUser({ teamId: group.teamId });
|
||||||
|
|
||||||
|
await GroupPermission.create({
|
||||||
|
createdById: user.id,
|
||||||
|
groupId: group.id,
|
||||||
|
collectionId: collection.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
const permission = await GroupPermission.scope("withCollection").findOne({
|
||||||
|
where: {
|
||||||
|
groupId: group.id,
|
||||||
|
collectionId: collection.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(permission).toBeDefined();
|
||||||
|
expect(permission?.collection).toBeDefined();
|
||||||
|
expect(permission?.collection?.id).toEqual(collection.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -26,15 +26,14 @@ import Fix from "./decorators/Fix";
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
withCollection: {
|
withCollection: {
|
||||||
|
where: {
|
||||||
|
collectionId: {
|
||||||
|
[Op.ne]: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Collection,
|
association: "collection",
|
||||||
as: "collection",
|
|
||||||
where: {
|
|
||||||
collectionId: {
|
|
||||||
[Op.ne]: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
28
server/models/UserPermission.test.ts
Normal file
28
server/models/UserPermission.test.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { buildCollection, buildUser } from "@server/test/factories";
|
||||||
|
import UserPermission from "./UserPermission";
|
||||||
|
|
||||||
|
describe("UserPermission", () => {
|
||||||
|
describe("withCollection scope", () => {
|
||||||
|
it("should return the collection", async () => {
|
||||||
|
const collection = await buildCollection();
|
||||||
|
const user = await buildUser({ teamId: collection.teamId });
|
||||||
|
|
||||||
|
await UserPermission.create({
|
||||||
|
createdById: user.id,
|
||||||
|
userId: user.id,
|
||||||
|
collectionId: collection.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
const permission = await UserPermission.scope("withCollection").findOne({
|
||||||
|
where: {
|
||||||
|
userId: user.id,
|
||||||
|
collectionId: collection.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(permission).toBeDefined();
|
||||||
|
expect(permission?.collection).toBeDefined();
|
||||||
|
expect(permission?.collection?.id).toEqual(collection.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -25,15 +25,14 @@ import Fix from "./decorators/Fix";
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
withCollection: {
|
withCollection: {
|
||||||
|
where: {
|
||||||
|
collectionId: {
|
||||||
|
[Op.ne]: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Collection,
|
association: "collection",
|
||||||
as: "collection",
|
|
||||||
where: {
|
|
||||||
collectionId: {
|
|
||||||
[Op.ne]: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user