blob: f1ae478baf0b8d370f5ccd8a68536460c6857850 [file] [log] [blame]
Xing Jinwen9d585b32025-06-08 03:08:53 +08001{
2 "info": {
3 "name": "PT站分享率功能完整测试",
4 "description": "测试PT站的分享率计算、下载权限检查和VIP自动升级功能",
5 "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
6 },
7 "variable": [
8 {
9 "key": "base_url",
10 "value": "http://localhost:8081/api",
11 "type": "string"
12 },
13 {
14 "key": "token",
15 "value": "",
16 "type": "string"
17 }
18 ],
19 "item": [
20 {
21 "name": "测试场景1: 分享率过低用户",
22 "item": [
23 {
24 "name": "1.1 登录低分享率用户",
25 "event": [
26 {
27 "listen": "test",
28 "script": {
29 "exec": [
30 "pm.test('登录成功', function () {",
31 " pm.expect(pm.response.code).to.equal(200);",
32 "});",
33 "",
34 "if (pm.response.code === 200) {",
35 " const response = pm.response.json();",
36 " if (response.tokenInfo && response.tokenInfo.tokenValue) {",
37 " pm.collectionVariables.set('token', response.tokenInfo.tokenValue);",
38 " console.log('Token saved:', response.tokenInfo.tokenValue);",
39 " }",
40 "}"
41 ]
42 }
43 }
44 ],
45 "request": {
46 "method": "POST",
47 "header": [
48 {
49 "key": "Content-Type",
50 "value": "application/json"
51 }
52 ],
53 "body": {
54 "mode": "raw",
55 "raw": "{\n \"user\": \"你的测试用户名1\",\n \"password\": \"你的密码\"\n}"
56 },
57 "url": {
58 "raw": "{{base_url}}/auth/login",
59 "host": ["{{base_url}}"],
60 "path": ["auth", "login"]
61 }
62 }
63 },
64 {
65 "name": "1.2 查看分享率信息",
66 "event": [
67 {
68 "listen": "test",
69 "script": {
70 "exec": [
71 "pm.test('获取分享率信息成功', function () {",
72 " pm.expect(pm.response.code).to.equal(200);",
73 "});",
74 "",
75 "const response = pm.response.json();",
76 "console.log('分享率信息:', JSON.stringify(response, null, 2));",
77 "",
78 "pm.test('分享率过低', function () {",
79 " pm.expect(response.shareRatio).to.be.below(0.3);",
80 "});",
81 "",
82 "pm.test('不能下载', function () {",
83 " pm.expect(response.canDownload).to.be.false;",
84 "});",
85 "",
86 "pm.test('不是VIP用户', function () {",
87 " pm.expect(response.isVip).to.be.false;",
88 "});"
89 ]
90 }
91 }
92 ],
93 "request": {
94 "method": "GET",
95 "header": [
96 {
97 "key": "sapling-token",
98 "value": "{{token}}"
99 }
100 ],
101 "url": {
102 "raw": "{{base_url}}/torrent/ratio/info",
103 "host": ["{{base_url}}"],
104 "path": ["torrent", "ratio", "info"]
105 }
106 }
107 },
108 {
109 "name": "1.3 尝试下载种子(应该被拒绝)",
110 "event": [
111 {
112 "listen": "test",
113 "script": {
114 "exec": [
115 "pm.test('下载被拒绝', function () {",
116 " pm.expect(pm.response.code).to.equal(403);",
117 "});",
118 "",
119 "const response = pm.response.json();",
120 "console.log('下载拒绝信息:', JSON.stringify(response, null, 2));",
121 "",
122 "pm.test('返回正确的错误信息', function () {",
123 " pm.expect(response.error).to.equal('下载权限不足');",
124 " pm.expect(response.currentRatio).to.be.below(0.3);",
125 " pm.expect(response.requiredRatio).to.equal(0.3);",
126 "});"
127 ]
128 }
129 }
130 ],
131 "request": {
132 "method": "GET",
133 "header": [
134 {
135 "key": "sapling-token",
136 "value": "{{token}}"
137 }
138 ],
139 "url": {
140 "raw": "{{base_url}}/torrent/download/1",
141 "host": ["{{base_url}}"],
142 "path": ["torrent", "download", "1"]
143 }
144 }
145 }
146 ]
147 },
148 {
149 "name": "测试场景2: 正常分享率用户",
150 "item": [
151 {
152 "name": "2.1 登录正常用户",
153 "event": [
154 {
155 "listen": "test",
156 "script": {
157 "exec": [
158 "pm.test('登录成功', function () {",
159 " pm.expect(pm.response.code).to.equal(200);",
160 "});",
161 "",
162 "if (pm.response.code === 200) {",
163 " const response = pm.response.json();",
164 " if (response.tokenInfo && response.tokenInfo.tokenValue) {",
165 " pm.collectionVariables.set('token', response.tokenInfo.tokenValue);",
166 " }",
167 "}"
168 ]
169 }
170 }
171 ],
172 "request": {
173 "method": "POST",
174 "header": [
175 {
176 "key": "Content-Type",
177 "value": "application/json"
178 }
179 ],
180 "body": {
181 "mode": "raw",
182 "raw": "{\n \"user\": \"你的测试用户名2\",\n \"password\": \"你的密码\"\n}"
183 },
184 "url": {
185 "raw": "{{base_url}}/auth/login",
186 "host": ["{{base_url}}"],
187 "path": ["auth", "login"]
188 }
189 }
190 },
191 {
192 "name": "2.2 查看分享率信息",
193 "event": [
194 {
195 "listen": "test",
196 "script": {
197 "exec": [
198 "const response = pm.response.json();",
199 "console.log('正常用户分享率信息:', JSON.stringify(response, null, 2));",
200 "",
201 "pm.test('分享率正常', function () {",
202 " pm.expect(response.shareRatio).to.be.at.least(0.3);",
203 " pm.expect(response.shareRatio).to.be.below(2.0);",
204 "});",
205 "",
206 "pm.test('可以下载', function () {",
207 " pm.expect(response.canDownload).to.be.true;",
208 "});",
209 "",
210 "pm.test('还不是VIP用户', function () {",
211 " pm.expect(response.isVip).to.be.false;",
212 "});"
213 ]
214 }
215 }
216 ],
217 "request": {
218 "method": "GET",
219 "header": [
220 {
221 "key": "sapling-token",
222 "value": "{{token}}"
223 }
224 ],
225 "url": {
226 "raw": "{{base_url}}/torrent/ratio/info",
227 "host": ["{{base_url}}"],
228 "path": ["torrent", "ratio", "info"]
229 }
230 }
231 },
232 {
233 "name": "2.3 下载种子(应该成功)",
234 "event": [
235 {
236 "listen": "test",
237 "script": {
238 "exec": [
239 "pm.test('下载成功或种子不存在', function () {",
240 " // 如果种子存在,应该返回200和二进制数据",
241 " // 如果种子不存在,返回404",
242 " pm.expect([200, 404]).to.include(pm.response.code);",
243 "});",
244 "",
245 "if (pm.response.code === 200) {",
246 " pm.test('返回种子文件', function () {",
247 " pm.expect(pm.response.headers.get('Content-Type')).to.equal('application/octet-stream');",
248 " });",
249 " console.log('种子下载成功');",
250 "} else if (pm.response.code === 404) {",
251 " console.log('种子不存在,但下载权限检查通过');",
252 "}"
253 ]
254 }
255 }
256 ],
257 "request": {
258 "method": "GET",
259 "header": [
260 {
261 "key": "sapling-token",
262 "value": "{{token}}"
263 }
264 ],
265 "url": {
266 "raw": "{{base_url}}/torrent/download/1",
267 "host": ["{{base_url}}"],
268 "path": ["torrent", "download", "1"]
269 }
270 }
271 }
272 ]
273 },
274 {
275 "name": "测试场景3: 高分享率用户自动升级VIP",
276 "item": [
277 {
278 "name": "3.1 登录高分享率用户",
279 "event": [
280 {
281 "listen": "test",
282 "script": {
283 "exec": [
284 "pm.test('登录成功', function () {",
285 " pm.expect(pm.response.code).to.equal(200);",
286 "});",
287 "",
288 "if (pm.response.code === 200) {",
289 " const response = pm.response.json();",
290 " if (response.tokenInfo && response.tokenInfo.tokenValue) {",
291 " pm.collectionVariables.set('token', response.tokenInfo.tokenValue);",
292 " }",
293 "}"
294 ]
295 }
296 }
297 ],
298 "request": {
299 "method": "POST",
300 "header": [
301 {
302 "key": "Content-Type",
303 "value": "application/json"
304 }
305 ],
306 "body": {
307 "mode": "raw",
308 "raw": "{\n \"user\": \"你的测试用户名3\",\n \"password\": \"你的密码\"\n}"
309 },
310 "url": {
311 "raw": "{{base_url}}/auth/login",
312 "host": ["{{base_url}}"],
313 "path": ["auth", "login"]
314 }
315 }
316 },
317 {
318 "name": "3.2 查看升级前分享率信息",
319 "event": [
320 {
321 "listen": "test",
322 "script": {
323 "exec": [
324 "const response = pm.response.json();",
325 "console.log('升级前分享率信息:', JSON.stringify(response, null, 2));",
326 "",
327 "pm.test('分享率很高', function () {",
328 " pm.expect(response.shareRatio).to.be.at.least(2.0);",
329 "});",
330 "",
331 "// 记录升级前状态",
332 "pm.collectionVariables.set('beforeUpgradeIsVip', response.isVip);"
333 ]
334 }
335 }
336 ],
337 "request": {
338 "method": "GET",
339 "header": [
340 {
341 "key": "sapling-token",
342 "value": "{{token}}"
343 }
344 ],
345 "url": {
346 "raw": "{{base_url}}/torrent/ratio/info",
347 "host": ["{{base_url}}"],
348 "path": ["torrent", "ratio", "info"]
349 }
350 }
351 },
352 {
353 "name": "3.3 触发VIP检查(下载种子)",
354 "event": [
355 {
356 "listen": "test",
357 "script": {
358 "exec": [
359 "// 这个请求主要是触发ShareRatioService.checkAndUpdateVipStatus",
360 "console.log('触发VIP状态检查,响应码:', pm.response.code);"
361 ]
362 }
363 }
364 ],
365 "request": {
366 "method": "GET",
367 "header": [
368 {
369 "key": "sapling-token",
370 "value": "{{token}}"
371 }
372 ],
373 "url": {
374 "raw": "{{base_url}}/torrent/download/1",
375 "host": ["{{base_url}}"],
376 "path": ["torrent", "download", "1"]
377 }
378 }
379 },
380 {
381 "name": "3.4 验证VIP升级结果",
382 "event": [
383 {
384 "listen": "test",
385 "script": {
386 "exec": [
387 "const response = pm.response.json();",
388 "console.log('升级后分享率信息:', JSON.stringify(response, null, 2));",
389 "",
390 "pm.test('已升级为VIP', function () {",
391 " pm.expect(response.isVip).to.be.true;",
392 "});",
393 "",
394 "pm.test('VIP用户可以下载', function () {",
395 " pm.expect(response.canDownload).to.be.true;",
396 "});",
397 "",
398 "pm.test('用户组显示为VIP', function () {",
399 " pm.expect(response.groupName).to.include('VIP');",
400 "});"
401 ]
402 }
403 }
404 ],
405 "request": {
406 "method": "GET",
407 "header": [
408 {
409 "key": "sapling-token",
410 "value": "{{token}}"
411 }
412 ],
413 "url": {
414 "raw": "{{base_url}}/torrent/ratio/info",
415 "host": ["{{base_url}}"],
416 "path": ["torrent", "ratio", "info"]
417 }
418 }
419 }
420 ]
421 },
422 {
423 "name": "测试场景4: 数据库验证",
424 "item": [
425 {
426 "name": "4.1 验证数据库中的group_id变化",
427 "event": [
428 {
429 "listen": "test",
430 "script": {
431 "exec": [
432 "// 这是一个提示性的测试项",
433 "// 实际验证需要在数据库中执行SQL查询",
434 "console.log('请在数据库中执行以下SQL来验证group_id变化:');",
435 "console.log('SELECT id, username, uploaded, downloaded, group_id, ROUND(uploaded/downloaded, 3) as share_ratio FROM users WHERE id IN (1,2,3,4);');"
436 ]
437 }
438 }
439 ],
440 "request": {
441 "method": "GET",
442 "header": [],
443 "url": {
444 "raw": "{{base_url}}/auth/status",
445 "host": ["{{base_url}}"],
446 "path": ["auth", "status"]
447 }
448 }
449 }
450 ]
451 }
452 ]
453}