Skip to content

Commit 82e9bc0

Browse files
Update mockInteraction to handle permissions and roles properly
1 parent a245acd commit 82e9bc0

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

__tests__/mocks/mockInteraction.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ const teacher = {
7979
fetch: jest.fn(),
8080
remove: jest.fn((role) => teacher.roles.cache = teacher.roles.cache.filter(r => r.name !== role.name)),
8181
},
82+
permissions: {
83+
list: [],
84+
has(perm) {
85+
return this.list.includes(perm);
86+
},
87+
},
8288
_roles: [1, 3, 4],
8389
fetch: jest.fn(),
8490
displayName: "teacher",
@@ -97,6 +103,12 @@ const student = {
97103
fetch: jest.fn(),
98104
remove: jest.fn((role) => student.roles.cache = student.roles.cache.filter(r => r.name !== role.name)),
99105
},
106+
permissions: {
107+
list: [],
108+
has(perm) {
109+
return this.list.includes(perm);
110+
},
111+
},
100112
_roles: [3],
101113
fetch: jest.fn(),
102114
displayName: "student",
@@ -115,6 +127,12 @@ const admin = {
115127
fetch: jest.fn(),
116128
remove: jest.fn((role) => admin.roles.cache = admin.roles.cache.filter(r => r.name !== role.name)),
117129
},
130+
permissions: {
131+
list: ["ADMINISTRATOR"],
132+
has(perm) {
133+
return this.list.includes(perm);
134+
},
135+
},
118136
_roles: [2, 3],
119137
fetch: jest.fn(),
120138
displayName: "admin",
@@ -198,6 +216,15 @@ const defaultTeacherInteraction = {
198216
member: {
199217
user: teacher,
200218
_roles: [1, 3, 4],
219+
roles: {
220+
cache: teacher.roles.cache,
221+
},
222+
permissions: {
223+
list: [],
224+
has(perm) {
225+
return this.list.includes(perm);
226+
},
227+
},
201228
},
202229
options: undefined,
203230
reply: jest.fn(),
@@ -209,6 +236,15 @@ const defaultStudentInteraction = {
209236
member: {
210237
user: student,
211238
_roles: [1],
239+
roles: {
240+
cache: student.roles.cache,
241+
},
242+
permissions: {
243+
list: [],
244+
has(perm) {
245+
return this.list.includes(perm);
246+
},
247+
},
212248
},
213249
options: undefined,
214250
reply: jest.fn(),
@@ -221,6 +257,12 @@ const studentInteractionWithoutOptions = {
221257
user: {
222258
id: 2,
223259
},
260+
permissions: {
261+
list: [],
262+
has(perm) {
263+
return this.list.includes(perm);
264+
},
265+
},
224266
},
225267
options: undefined,
226268
};
@@ -231,7 +273,15 @@ const defaultAdminInteraction = {
231273
member: {
232274
user: admin,
233275
_roles: [2, 3],
234-
roles: [2, 3],
276+
roles: {
277+
cache: admin.roles.cache,
278+
},
279+
permissions: {
280+
list: ["ADMINISTRATOR"],
281+
has(perm) {
282+
return this.list.includes(perm);
283+
},
284+
},
235285
},
236286
options: undefined,
237287
commandName: "test",

0 commit comments

Comments
 (0)