@@ -20,6 +20,8 @@ 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
+
24
+ beforeEach ( ( ) => {
23
25
defaultTeacherInteraction . options = {
24
26
getString : jest . fn ( ( name ) => {
25
27
const names = {
@@ -40,7 +42,7 @@ defaultStudentInteraction.options = {
40
42
return names [ name ] ;
41
43
} ) ,
42
44
} ;
43
-
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
} ) ;
0 commit comments