| { | |
| "info": { | |
| "name": "PT站分享率功能完整测试", | |
| "description": "测试PT站的分享率计算、下载权限检查和VIP自动升级功能", | |
| "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" | |
| }, | |
| "variable": [ | |
| { | |
| "key": "base_url", | |
| "value": "http://localhost:8081/api", | |
| "type": "string" | |
| }, | |
| { | |
| "key": "token", | |
| "value": "", | |
| "type": "string" | |
| } | |
| ], | |
| "item": [ | |
| { | |
| "name": "测试场景1: 分享率过低用户", | |
| "item": [ | |
| { | |
| "name": "1.1 登录低分享率用户", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "pm.test('登录成功', function () {", | |
| " pm.expect(pm.response.code).to.equal(200);", | |
| "});", | |
| "", | |
| "if (pm.response.code === 200) {", | |
| " const response = pm.response.json();", | |
| " if (response.tokenInfo && response.tokenInfo.tokenValue) {", | |
| " pm.collectionVariables.set('token', response.tokenInfo.tokenValue);", | |
| " console.log('Token saved:', response.tokenInfo.tokenValue);", | |
| " }", | |
| "}" | |
| ] | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "POST", | |
| "header": [ | |
| { | |
| "key": "Content-Type", | |
| "value": "application/json" | |
| } | |
| ], | |
| "body": { | |
| "mode": "raw", | |
| "raw": "{\n \"user\": \"你的测试用户名1\",\n \"password\": \"你的密码\"\n}" | |
| }, | |
| "url": { | |
| "raw": "{{base_url}}/auth/login", | |
| "host": ["{{base_url}}"], | |
| "path": ["auth", "login"] | |
| } | |
| } | |
| }, | |
| { | |
| "name": "1.2 查看分享率信息", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "pm.test('获取分享率信息成功', function () {", | |
| " pm.expect(pm.response.code).to.equal(200);", | |
| "});", | |
| "", | |
| "const response = pm.response.json();", | |
| "console.log('分享率信息:', JSON.stringify(response, null, 2));", | |
| "", | |
| "pm.test('分享率过低', function () {", | |
| " pm.expect(response.shareRatio).to.be.below(0.3);", | |
| "});", | |
| "", | |
| "pm.test('不能下载', function () {", | |
| " pm.expect(response.canDownload).to.be.false;", | |
| "});", | |
| "", | |
| "pm.test('不是VIP用户', function () {", | |
| " pm.expect(response.isVip).to.be.false;", | |
| "});" | |
| ] | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "GET", | |
| "header": [ | |
| { | |
| "key": "sapling-token", | |
| "value": "{{token}}" | |
| } | |
| ], | |
| "url": { | |
| "raw": "{{base_url}}/torrent/ratio/info", | |
| "host": ["{{base_url}}"], | |
| "path": ["torrent", "ratio", "info"] | |
| } | |
| } | |
| }, | |
| { | |
| "name": "1.3 尝试下载种子(应该被拒绝)", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "pm.test('下载被拒绝', function () {", | |
| " pm.expect(pm.response.code).to.equal(403);", | |
| "});", | |
| "", | |
| "const response = pm.response.json();", | |
| "console.log('下载拒绝信息:', JSON.stringify(response, null, 2));", | |
| "", | |
| "pm.test('返回正确的错误信息', function () {", | |
| " pm.expect(response.error).to.equal('下载权限不足');", | |
| " pm.expect(response.currentRatio).to.be.below(0.3);", | |
| " pm.expect(response.requiredRatio).to.equal(0.3);", | |
| "});" | |
| ] | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "GET", | |
| "header": [ | |
| { | |
| "key": "sapling-token", | |
| "value": "{{token}}" | |
| } | |
| ], | |
| "url": { | |
| "raw": "{{base_url}}/torrent/download/1", | |
| "host": ["{{base_url}}"], | |
| "path": ["torrent", "download", "1"] | |
| } | |
| } | |
| } | |
| ] | |
| }, | |
| { | |
| "name": "测试场景2: 正常分享率用户", | |
| "item": [ | |
| { | |
| "name": "2.1 登录正常用户", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "pm.test('登录成功', function () {", | |
| " pm.expect(pm.response.code).to.equal(200);", | |
| "});", | |
| "", | |
| "if (pm.response.code === 200) {", | |
| " const response = pm.response.json();", | |
| " if (response.tokenInfo && response.tokenInfo.tokenValue) {", | |
| " pm.collectionVariables.set('token', response.tokenInfo.tokenValue);", | |
| " }", | |
| "}" | |
| ] | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "POST", | |
| "header": [ | |
| { | |
| "key": "Content-Type", | |
| "value": "application/json" | |
| } | |
| ], | |
| "body": { | |
| "mode": "raw", | |
| "raw": "{\n \"user\": \"你的测试用户名2\",\n \"password\": \"你的密码\"\n}" | |
| }, | |
| "url": { | |
| "raw": "{{base_url}}/auth/login", | |
| "host": ["{{base_url}}"], | |
| "path": ["auth", "login"] | |
| } | |
| } | |
| }, | |
| { | |
| "name": "2.2 查看分享率信息", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "const response = pm.response.json();", | |
| "console.log('正常用户分享率信息:', JSON.stringify(response, null, 2));", | |
| "", | |
| "pm.test('分享率正常', function () {", | |
| " pm.expect(response.shareRatio).to.be.at.least(0.3);", | |
| " pm.expect(response.shareRatio).to.be.below(2.0);", | |
| "});", | |
| "", | |
| "pm.test('可以下载', function () {", | |
| " pm.expect(response.canDownload).to.be.true;", | |
| "});", | |
| "", | |
| "pm.test('还不是VIP用户', function () {", | |
| " pm.expect(response.isVip).to.be.false;", | |
| "});" | |
| ] | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "GET", | |
| "header": [ | |
| { | |
| "key": "sapling-token", | |
| "value": "{{token}}" | |
| } | |
| ], | |
| "url": { | |
| "raw": "{{base_url}}/torrent/ratio/info", | |
| "host": ["{{base_url}}"], | |
| "path": ["torrent", "ratio", "info"] | |
| } | |
| } | |
| }, | |
| { | |
| "name": "2.3 下载种子(应该成功)", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "pm.test('下载成功或种子不存在', function () {", | |
| " // 如果种子存在,应该返回200和二进制数据", | |
| " // 如果种子不存在,返回404", | |
| " pm.expect([200, 404]).to.include(pm.response.code);", | |
| "});", | |
| "", | |
| "if (pm.response.code === 200) {", | |
| " pm.test('返回种子文件', function () {", | |
| " pm.expect(pm.response.headers.get('Content-Type')).to.equal('application/octet-stream');", | |
| " });", | |
| " console.log('种子下载成功');", | |
| "} else if (pm.response.code === 404) {", | |
| " console.log('种子不存在,但下载权限检查通过');", | |
| "}" | |
| ] | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "GET", | |
| "header": [ | |
| { | |
| "key": "sapling-token", | |
| "value": "{{token}}" | |
| } | |
| ], | |
| "url": { | |
| "raw": "{{base_url}}/torrent/download/1", | |
| "host": ["{{base_url}}"], | |
| "path": ["torrent", "download", "1"] | |
| } | |
| } | |
| } | |
| ] | |
| }, | |
| { | |
| "name": "测试场景3: 高分享率用户自动升级VIP", | |
| "item": [ | |
| { | |
| "name": "3.1 登录高分享率用户", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "pm.test('登录成功', function () {", | |
| " pm.expect(pm.response.code).to.equal(200);", | |
| "});", | |
| "", | |
| "if (pm.response.code === 200) {", | |
| " const response = pm.response.json();", | |
| " if (response.tokenInfo && response.tokenInfo.tokenValue) {", | |
| " pm.collectionVariables.set('token', response.tokenInfo.tokenValue);", | |
| " }", | |
| "}" | |
| ] | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "POST", | |
| "header": [ | |
| { | |
| "key": "Content-Type", | |
| "value": "application/json" | |
| } | |
| ], | |
| "body": { | |
| "mode": "raw", | |
| "raw": "{\n \"user\": \"你的测试用户名3\",\n \"password\": \"你的密码\"\n}" | |
| }, | |
| "url": { | |
| "raw": "{{base_url}}/auth/login", | |
| "host": ["{{base_url}}"], | |
| "path": ["auth", "login"] | |
| } | |
| } | |
| }, | |
| { | |
| "name": "3.2 查看升级前分享率信息", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "const response = pm.response.json();", | |
| "console.log('升级前分享率信息:', JSON.stringify(response, null, 2));", | |
| "", | |
| "pm.test('分享率很高', function () {", | |
| " pm.expect(response.shareRatio).to.be.at.least(2.0);", | |
| "});", | |
| "", | |
| "// 记录升级前状态", | |
| "pm.collectionVariables.set('beforeUpgradeIsVip', response.isVip);" | |
| ] | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "GET", | |
| "header": [ | |
| { | |
| "key": "sapling-token", | |
| "value": "{{token}}" | |
| } | |
| ], | |
| "url": { | |
| "raw": "{{base_url}}/torrent/ratio/info", | |
| "host": ["{{base_url}}"], | |
| "path": ["torrent", "ratio", "info"] | |
| } | |
| } | |
| }, | |
| { | |
| "name": "3.3 触发VIP检查(下载种子)", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "// 这个请求主要是触发ShareRatioService.checkAndUpdateVipStatus", | |
| "console.log('触发VIP状态检查,响应码:', pm.response.code);" | |
| ] | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "GET", | |
| "header": [ | |
| { | |
| "key": "sapling-token", | |
| "value": "{{token}}" | |
| } | |
| ], | |
| "url": { | |
| "raw": "{{base_url}}/torrent/download/1", | |
| "host": ["{{base_url}}"], | |
| "path": ["torrent", "download", "1"] | |
| } | |
| } | |
| }, | |
| { | |
| "name": "3.4 验证VIP升级结果", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "const response = pm.response.json();", | |
| "console.log('升级后分享率信息:', JSON.stringify(response, null, 2));", | |
| "", | |
| "pm.test('已升级为VIP', function () {", | |
| " pm.expect(response.isVip).to.be.true;", | |
| "});", | |
| "", | |
| "pm.test('VIP用户可以下载', function () {", | |
| " pm.expect(response.canDownload).to.be.true;", | |
| "});", | |
| "", | |
| "pm.test('用户组显示为VIP', function () {", | |
| " pm.expect(response.groupName).to.include('VIP');", | |
| "});" | |
| ] | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "GET", | |
| "header": [ | |
| { | |
| "key": "sapling-token", | |
| "value": "{{token}}" | |
| } | |
| ], | |
| "url": { | |
| "raw": "{{base_url}}/torrent/ratio/info", | |
| "host": ["{{base_url}}"], | |
| "path": ["torrent", "ratio", "info"] | |
| } | |
| } | |
| } | |
| ] | |
| }, | |
| { | |
| "name": "测试场景4: 数据库验证", | |
| "item": [ | |
| { | |
| "name": "4.1 验证数据库中的group_id变化", | |
| "event": [ | |
| { | |
| "listen": "test", | |
| "script": { | |
| "exec": [ | |
| "// 这是一个提示性的测试项", | |
| "// 实际验证需要在数据库中执行SQL查询", | |
| "console.log('请在数据库中执行以下SQL来验证group_id变化:');", | |
| "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);');" | |
| ] | |
| } | |
| } | |
| ], | |
| "request": { | |
| "method": "GET", | |
| "header": [], | |
| "url": { | |
| "raw": "{{base_url}}/auth/status", | |
| "host": ["{{base_url}}"], | |
| "path": ["auth", "status"] | |
| } | |
| } | |
| } | |
| ] | |
| } | |
| ] | |
| } |