@@ -20,27 +20,29 @@ findCourseFromDb
20
20
createCourseToDatabase . mockImplementation ( ( ) => { return { name : "nickname" , id : Math . floor ( Math . random ( ) * 10 ) + 5 } ; } ) ;
21
21
22
22
const { defaultTeacherInteraction, defaultStudentInteraction } = require ( "../../mocks/mockInteraction" ) ;
23
- defaultTeacherInteraction . options = {
24
- getString : jest . fn ( ( name ) => {
25
- const names = {
26
- coursecode : "TKT-100" ,
27
- full_name : "Long course name" ,
28
- nick_name : "nickname" ,
29
- } ;
30
- return names [ name ] ;
31
- } ) ,
32
- } ;
33
23
34
- defaultStudentInteraction . options = {
35
- getString : jest . fn ( ( name ) => {
36
- const names = {
37
- coursecode : "TKT-100" ,
38
- full_name : "Long course name" ,
39
- } ;
40
- return names [ name ] ;
41
- } ) ,
42
- } ;
24
+ beforeEach ( ( ) => {
25
+ defaultTeacherInteraction . options = {
26
+ getString : jest . fn ( ( name ) => {
27
+ const names = {
28
+ coursecode : "TKT-100" ,
29
+ full_name : "Long course name" ,
30
+ nick_name : "nickname" ,
31
+ } ;
32
+ return names [ name ] ;
33
+ } ) ,
34
+ } ;
43
35
36
+ defaultStudentInteraction . options = {
37
+ getString : jest . fn ( ( name ) => {
38
+ const names = {
39
+ coursecode : "TKT-100" ,
40
+ full_name : "Long course name" ,
41
+ } ;
42
+ return names [ name ] ;
43
+ } ) ,
44
+ } ;
45
+ } ) ;
44
46
afterEach ( ( ) => {
45
47
jest . clearAllMocks ( ) ;
46
48
} ) ;
@@ -65,19 +67,39 @@ describe("slash create command", () => {
65
67
} ) ;
66
68
67
69
test ( "course code must be unique when nickname not given" , async ( ) => {
68
- const client = defaultStudentInteraction . client ;
70
+ defaultTeacherInteraction . options = {
71
+ getString : jest . fn ( ( name ) => {
72
+ const names = {
73
+ coursecode : "TKT-100" ,
74
+ full_name : "Long course name" ,
75
+ nick_name : undefined ,
76
+ } ;
77
+ return names [ name ] ;
78
+ } ) ,
79
+ } ;
80
+ const client = defaultTeacherInteraction . client ;
69
81
const response = "Course code must be unique." ;
70
- await execute ( defaultStudentInteraction , client , models ) ;
82
+ await execute ( defaultTeacherInteraction , client , models ) ;
71
83
expect ( findCourseFromDbWithFullName ) . toHaveBeenCalledTimes ( 1 ) ;
72
84
expect ( sendErrorEphemeral ) . toHaveBeenCalledTimes ( 1 ) ;
73
- expect ( sendErrorEphemeral ) . toHaveBeenCalledWith ( defaultStudentInteraction , response ) ;
85
+ expect ( sendErrorEphemeral ) . toHaveBeenCalledWith ( defaultTeacherInteraction , response ) ;
74
86
} ) ;
75
87
76
88
test ( "create course name without nick" , async ( ) => {
89
+ defaultTeacherInteraction . options = {
90
+ getString : jest . fn ( ( name ) => {
91
+ const names = {
92
+ coursecode : "TKT-100" ,
93
+ full_name : "Long course name" ,
94
+ nick_name : undefined ,
95
+ } ;
96
+ return names [ name ] ;
97
+ } ) ,
98
+ } ;
77
99
const courseCode = "TKT-100" ;
78
100
const fullName = "Long course name" ;
79
- const client = defaultStudentInteraction . client ;
80
- await execute ( defaultStudentInteraction , client , models ) ;
101
+ const client = defaultTeacherInteraction . client ;
102
+ await execute ( defaultTeacherInteraction , client , models ) ;
81
103
expect ( createCourseToDatabase ) . toHaveBeenCalledTimes ( 1 ) ;
82
104
expect ( createCourseToDatabase ) . toHaveBeenCalledWith ( courseCode , fullName , courseCode . toLowerCase ( ) , models . Course ) ;
83
105
} ) ;
@@ -138,4 +160,11 @@ describe("slash create command", () => {
138
160
expect ( sendErrorEphemeral ) . toHaveBeenCalledWith ( defaultTeacherInteraction , "Emojis are not allowed!" ) ;
139
161
} ) ;
140
162
163
+ test ( "a student cannot use faculty command" , async ( ) => {
164
+ const client = defaultStudentInteraction . client ;
165
+ const response = "You do not have permission to use this command." ;
166
+ await execute ( defaultStudentInteraction , client , models ) ;
167
+ expect ( sendErrorEphemeral ) . toHaveBeenCalledTimes ( 1 ) ;
168
+ expect ( sendErrorEphemeral ) . toHaveBeenCalledWith ( defaultStudentInteraction , response ) ;
169
+ } ) ;
141
170
} ) ;
0 commit comments