Skip to content

Commit e340138

Browse files
committed
refactor: custom course
1 parent a132285 commit e340138

14 files changed

Lines changed: 281 additions & 339 deletions

File tree

api/handler/api/course_service.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/handler/api/course_service_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestGetCourseList(t *testing.T) {
5555
type testCase struct {
5656
name string
5757
url string
58-
mockResp []*model.Course
58+
mockResp *course.CourseListResponse
5959
mockErr error
6060
expectContains string
6161
}
@@ -64,7 +64,7 @@ func TestGetCourseList(t *testing.T) {
6464
{
6565
name: "success",
6666
url: "/api/v1/jwch/course/list?term=202401",
67-
mockResp: []*model.Course{},
67+
mockResp: &course.CourseListResponse{Data: []*model.Course{}},
6868
expectContains: `{"code":"10000","message":"ok","data":[]}`,
6969
},
7070
{
@@ -86,7 +86,7 @@ func TestGetCourseList(t *testing.T) {
8686
defer mockey.UnPatchAll()
8787
for _, tc := range testCases {
8888
mockey.PatchConvey(tc.name, t, func() {
89-
mockey.Mock(rpc.GetCourseListRPC).To(func(ctx context.Context, req *course.CourseListRequest) ([]*model.Course, error) {
89+
mockey.Mock(rpc.GetCourseListRPC).To(func(ctx context.Context, req *course.CourseListRequest) (*course.CourseListResponse, error) {
9090
return tc.mockResp, tc.mockErr
9191
}).Build()
9292

@@ -110,13 +110,13 @@ func TestGetCourseListV2(t *testing.T) {
110110
testCases := []testCase{
111111
{
112112
name: "success",
113-
url: "/api/v2/jwch/course/list?term=202401",
113+
url: "/api/v2/course/list?term=202401",
114114
mockResp: &course.CourseListResponse{Data: []*model.Course{}},
115115
expectContains: `{"code":"10000","message":"ok","data":{"base":null,"data":[],"custom_courses":[]}}`,
116116
},
117117
{
118118
name: "success",
119-
url: "/api/v2/jwch/course/list?term=202401",
119+
url: "/api/v2/course/list?term=202401",
120120
mockResp: &course.CourseListResponse{
121121
Data: []*model.Course{},
122122
CustomCourses: []*course.CustomCourseItem{
@@ -127,19 +127,19 @@ func TestGetCourseListV2(t *testing.T) {
127127
},
128128
{
129129
name: "rpc error",
130-
url: "/api/v2/jwch/course/list?term=202401",
130+
url: "/api/v2/course/list?term=202401",
131131
mockErr: errno.InternalServiceError,
132132
expectContains: `{"code":"50001","message":"内部服务错误"}`,
133133
},
134134
{
135135
name: "bind error",
136-
url: "/api/v2/jwch/course/list",
136+
url: "/api/v2/course/list",
137137
expectContains: `{"code":"20001","message":"参数错误,`,
138138
},
139139
}
140140

141141
router := route.NewEngine(&config.Options{})
142-
router.GET("/api/v2/jwch/course/list", GetCourseListV2)
142+
router.GET("/api/v2/course/list", GetCourseListV2)
143143

144144
defer mockey.UnPatchAll()
145145
for _, tc := range testCases {

0 commit comments

Comments
 (0)