mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-04 02:39:14 +02:00
fix:#46 added tests for UpdateCourse
This commit is contained in:
@@ -29,9 +29,9 @@ func TestUpdateCourse(t *testing.T) {
|
||||
events := model.Events{}
|
||||
|
||||
// Set up expectations
|
||||
mockCourseService.On("GetAllCourses").Return([]string{"Course1", "Course2"})
|
||||
mockEventService.On("UpdateModulesForCourse", "Course1").Return(events, nil)
|
||||
mockEventService.On("UpdateModulesForCourse", "Course2").Return(events, nil)
|
||||
mockCourseService.On("GetAllCoursesForSemester", "ss").Return([]model.SeminarGroup{{Course: "Course1", Semester: ""}, {Course: "Course2", Semester: ""}})
|
||||
mockEventService.On("UpdateModulesForCourse", model.SeminarGroup{Course: "Course1", Semester: ""}).Return(events, nil)
|
||||
mockEventService.On("UpdateModulesForCourse", model.SeminarGroup{Course: "Course2", Semester: ""}).Return(events, nil)
|
||||
|
||||
// Inject mocks into the UpdateCourse function
|
||||
service := serviceModel.Service{
|
||||
@@ -46,12 +46,12 @@ func TestUpdateCourse(t *testing.T) {
|
||||
mockEventService.AssertExpectations(t)
|
||||
|
||||
// Assert that the UpdateCourse function was called twice
|
||||
mockCourseService.AssertNumberOfCalls(t, "GetAllCourses", 1)
|
||||
mockCourseService.AssertNumberOfCalls(t, "GetAllCoursesForSemester", 1)
|
||||
mockEventService.AssertNumberOfCalls(t, "UpdateModulesForCourse", 2)
|
||||
|
||||
// Assert that the UpdateCourse function was called with the correct arguments
|
||||
mockEventService.AssertCalled(t, "UpdateModulesForCourse", "Course1")
|
||||
mockEventService.AssertCalled(t, "UpdateModulesForCourse", "Course2")
|
||||
mockEventService.AssertCalled(t, "UpdateModulesForCourse", model.SeminarGroup{Course: "Course1", Semester: ""})
|
||||
mockEventService.AssertCalled(t, "UpdateModulesForCourse", model.SeminarGroup{Course: "Course2", Semester: ""})
|
||||
}
|
||||
|
||||
func TestUpdateCourseErr(t *testing.T) {
|
||||
@@ -62,9 +62,9 @@ func TestUpdateCourseErr(t *testing.T) {
|
||||
events := model.Events{}
|
||||
|
||||
// Set up expectations
|
||||
mockCourseService.On("GetAllCourses").Return([]string{"Course1", "Course2"})
|
||||
mockEventService.On("UpdateModulesForCourse", "Course1").Return(events, fmt.Errorf("error"))
|
||||
mockEventService.On("UpdateModulesForCourse", "Course2").Return(events, fmt.Errorf("error"))
|
||||
mockCourseService.On("GetAllCoursesForSemester", "ss").Return([]model.SeminarGroup{{Course: "Course1", Semester: ""}, {Course: "Course2", Semester: ""}})
|
||||
mockEventService.On("UpdateModulesForCourse", model.SeminarGroup{Course: "Course1", Semester: ""}).Return(events, fmt.Errorf("error"))
|
||||
mockEventService.On("UpdateModulesForCourse", model.SeminarGroup{Course: "Course2", Semester: ""}).Return(events, fmt.Errorf("error"))
|
||||
|
||||
// Create a custom writer to capture log output
|
||||
customWriter := &CustomWriter{}
|
||||
@@ -87,7 +87,7 @@ func TestUpdateCourseErr(t *testing.T) {
|
||||
mockEventService.AssertExpectations(t)
|
||||
|
||||
// Assert that the UpdateCourse function was called twice
|
||||
mockCourseService.AssertNumberOfCalls(t, "GetAllCourses", 1)
|
||||
mockCourseService.AssertNumberOfCalls(t, "GetAllCoursesForSemester", 1)
|
||||
mockEventService.AssertNumberOfCalls(t, "UpdateModulesForCourse", 2)
|
||||
|
||||
// Check the captured log output for the expected messages
|
||||
|
Reference in New Issue
Block a user