@@ -53,7 +53,7 @@ func TestAcademicService_GetCreditV2(t *testing.T) {
5353 }
5454
5555 getCreditV2Patch := mockey .Mock ((* jwch .Student ).GetCreditV2 ).Return (
56- nil , fmt .Errorf ("network connection failed" ),
56+ nil , nil , fmt .Errorf ("network connection failed" ),
5757 ).Build ()
5858 defer getCreditV2Patch .UnPatch ()
5959
@@ -77,38 +77,38 @@ func TestAcademicService_GetCreditV2(t *testing.T) {
7777 }
7878
7979 // 构建预期的返回数据,包括超出部分的学分
80- expectedCreditStats := jwch.CreditResponse {
80+ // The jwch.GetCreditV2 returns []*jwch.CreditStatistics, not jwch.CreditResponse
81+ majorCredits := []* jwch.CreditStatistics {
8182 {
82- Type : "主修专业" ,
83- Data : []* jwch.CreditDetail {
84- {
85- Key : "公共基础必修课" ,
86- Value : "35.0/32.0(已修满)" , // 35.0 > 32.0,有超出部分
87- },
88- {
89- Key : "学科基础必修课" ,
90- Value : "54.0/54.5(还需0.5分)" ,
91- },
92- {
93- Key : "专业必修课" ,
94- Value : "50.0/44.0(已修满)" , // 50.0 > 44.0,有超出部分
95- },
96- {
97- Key : "专业选修课" ,
98- Value : "5.0/12.0(还需7.0分)" ,
99- },
100- // 用于验证"总计"的还需学分
101- // 总共还差:0.5 + 7.0 = 7.5
102- {
103- Key : "总计" ,
104- Value : "144.0/142.5(还需7.5分)" ,
105- },
106- },
83+ Type : "公共基础必修课" ,
84+ Gain : "35.0" ,
85+ Total : "32.0" ,
86+ },
87+ {
88+ Type : "学科基础必修课" ,
89+ Gain : "54.0" ,
90+ Total : "54.5" ,
91+ },
92+ {
93+ Type : "专业必修课" ,
94+ Gain : "50.0" ,
95+ Total : "44.0" ,
96+ },
97+ {
98+ Type : "专业选修课" ,
99+ Gain : "5.0" ,
100+ Total : "12.0" ,
101+ },
102+ {
103+ Type : "总计" ,
104+ Gain : "144.0" ,
105+ Total : "142.5" ,
107106 },
108107 }
109108
109+ // Mock jwch's GetCreditV2 to return the data
110110 getCreditV2Patch := mockey .Mock ((* jwch .Student ).GetCreditV2 ).Return (
111- expectedCreditStats , nil ,
111+ majorCredits , nil , nil , // majorCredits, minorCredits, error
112112 ).Build ()
113113 defer getCreditV2Patch .UnPatch ()
114114
@@ -126,13 +126,105 @@ func TestAcademicService_GetCreditV2(t *testing.T) {
126126 So ((* result )[0 ].Type , ShouldEqual , "主修专业" )
127127 // 验证有超出部分的学分
128128 So ((* result )[0 ].Data [0 ].Key , ShouldEqual , "公共基础必修课" )
129- So ((* result )[0 ].Data [0 ].Value , ShouldEqual , "35.0/32.0(已修满)" )
130- // 验证有超出部分的学分
131- So ((* result )[0 ].Data [2 ].Key , ShouldEqual , "专业必修课" )
132- So ((* result )[0 ].Data [2 ].Value , ShouldEqual , "50.0/44.0(已修满)" )
129+ So ((* result )[0 ].Data [0 ].Value , ShouldEqual , "35 / 32" )
133130 // 验证有超出部分时的"总计"行
134131 So ((* result )[0 ].Data [4 ].Key , ShouldEqual , "总计" )
135- So ((* result )[0 ].Data [4 ].Value , ShouldEqual , "144.0/142.5(还需7.5分)" )
132+ So ((* result )[0 ].Data [4 ].Value , ShouldEqual , "144 / 142.5 (还需 7.5 分)" )
133+ })
134+
135+ Convey ("should return both major and minor credits when available" , func () {
136+ // Given: 已登录用户且系统正常,有主修专业和辅修专业
137+ testLoginData := & model.LoginData {
138+ Id : "222200311" ,
139+ Cookies : "ASP.NET_SessionId=lzs1t42mpkml4ag2jrxvib4z" ,
140+ }
141+
142+ // 主修专业数据
143+ majorCredits := []* jwch.CreditStatistics {
144+ {
145+ Type : "公共基础必修课" ,
146+ Gain : "20.0" ,
147+ Total : "20.0" ,
148+ },
149+ {
150+ Type : "学科基础必修课" ,
151+ Gain : "25.0" ,
152+ Total : "24.0" ,
153+ },
154+ {
155+ Type : "专业选修课" ,
156+ Gain : "15.0" ,
157+ Total : "12.0" ,
158+ },
159+ {
160+ Type : "总计" ,
161+ Gain : "60.0" ,
162+ Total : "56.0" ,
163+ },
164+ }
165+
166+ // 辅修专业数据
167+ minorCredits := []* jwch.CreditStatistics {
168+ {
169+ Type : "辅修必修课" ,
170+ Gain : "15.0" ,
171+ Total : "18.0" ,
172+ },
173+ {
174+ Type : "辅修选修课" ,
175+ Gain : "12.0" ,
176+ Total : "10.0" ,
177+ },
178+ {
179+ Type : "总计" ,
180+ Gain : "27.0" ,
181+ Total : "28.0" ,
182+ },
183+ }
184+
185+ // Mock jwch's GetCreditV2 to return the data
186+ getCreditV2Patch := mockey .Mock ((* jwch .Student ).GetCreditV2 ).Return (
187+ majorCredits , minorCredits , nil , // majorCredits, minorCredits, error
188+ ).Build ()
189+ defer getCreditV2Patch .UnPatch ()
190+
191+ ctx := baseContext .WithLoginData (context .Background (), testLoginData )
192+ service := & AcademicService {ctx : ctx }
193+
194+ // When: 获取学分信息
195+ result , err := service .GetCreditV2 ()
196+
197+ // Then: 应该返回主修专业和辅修专业数据
198+ So (err , ShouldBeNil )
199+ So (result , ShouldNotBeNil )
200+ So (len (* result ), ShouldEqual , 2 )
201+
202+ // Check main major credits
203+ So ((* result )[0 ].Type , ShouldEqual , "主修专业" )
204+ // 验证刚好修满的学分
205+ So ((* result )[0 ].Data [0 ].Key , ShouldEqual , "公共基础必修课" )
206+ So ((* result )[0 ].Data [0 ].Value , ShouldEqual , "20 / 20" )
207+ // 验证有超出部分的学分
208+ So ((* result )[0 ].Data [1 ].Key , ShouldEqual , "学科基础必修课" )
209+ So ((* result )[0 ].Data [1 ].Value , ShouldEqual , "25 / 24" )
210+ // 验证有超出部分的学分
211+ So ((* result )[0 ].Data [2 ].Key , ShouldEqual , "专业选修课" )
212+ So ((* result )[0 ].Data [2 ].Value , ShouldEqual , "15 / 12" )
213+ // 验证有超出部分时的"总计"行
214+ So ((* result )[0 ].Data [3 ].Key , ShouldEqual , "总计" )
215+ So ((* result )[0 ].Data [3 ].Value , ShouldEqual , "60 / 56" )
216+
217+ // Check minor credits
218+ So ((* result )[1 ].Type , ShouldEqual , "辅修专业" )
219+ // 验证未修满的学分
220+ So ((* result )[1 ].Data [0 ].Key , ShouldEqual , "辅修必修课" )
221+ So ((* result )[1 ].Data [0 ].Value , ShouldEqual , "15 / 18 (还需 3 分)" )
222+ // 验证有超出部分的学分
223+ So ((* result )[1 ].Data [1 ].Key , ShouldEqual , "辅修选修课" )
224+ So ((* result )[1 ].Data [1 ].Value , ShouldEqual , "12 / 10" )
225+ // 验证有超出部分时的"总计"行
226+ So ((* result )[1 ].Data [2 ].Key , ShouldEqual , "总计" )
227+ So ((* result )[1 ].Data [2 ].Value , ShouldEqual , "27 / 28 (还需 3 分)" )
136228 })
137229 })
138230}
0 commit comments