{ "info": { "name": "模板执行API测试集合", "description": "测试原有API和新的统一异步架构API", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "variable": [ { "key": "baseUrl", "value": "http://localhost:3003", "type": "string" }, { "key": "imageUrl", "value": "https://cdn.roasmax.cn/upload/676d85ae7c6347f49700631c84a13051.jpg", "type": "string" }, { "key": "authorization", "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI5OWQ3ZGZmOS02YWEwLTRmMWEtODA3YS01OTQ4Mzg3YTljNjkiLCJ1bmlmaWVkVXNlcklkIjoidXNlcl8xNzU2OTg0ODA1Mjk5X3l0M2hkMHZvayIsInBsYXRmb3JtIjoiYnl0ZWRhbmNlIiwiaWF0IjoxNzU3MDU3MTYwLCJleHAiOjE3NTcxNDM1NjB9.C0RF3wGw-bjzaCCGUeu2KgOGFlIGkqFZe28KgxLgjqU", "type": "string" }, { "key": "executionId", "value": "", "type": "string" } ], "item": [ { "name": "1. 原有同步API", "event": [ { "listen": "test", "script": { "exec": [ "// 检查响应状态", "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "// 检查响应时间", "pm.test(\"Response time is less than 10000ms\", function () {", " pm.expect(pm.response.responseTime).to.be.below(10000);", "});", "", "// 检查响应结构", "pm.test(\"Response has correct structure\", function () {", " var jsonData = pm.response.json();", " pm.expect(jsonData).to.have.property('code');", " pm.expect(jsonData).to.have.property('message');", " pm.expect(jsonData).to.have.property('data');", "});", "", "// 记录响应时间", "console.log('原有API响应时间: ' + pm.response.responseTime + 'ms');" ], "type": "text/javascript" } } ], "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" }, { "key": "Authorization", "value": "{{authorization}}" } ], "body": { "mode": "raw", "raw": "{\n \"imageUrl\": \"{{imageUrl}}\"\n}" }, "url": { "raw": "{{baseUrl}}/api/v1/templates/code/photo_restore_v1/execute", "host": ["{{baseUrl}}"], "path": ["api", "v1", "templates", "code", "photo_restore_v1", "execute"] }, "description": "测试原有的同步模板执行API" } }, { "name": "2. 新的异步API - 提交任务", "event": [ { "listen": "test", "script": { "exec": [ "// 检查响应状态", "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "// 检查响应时间(应该很快)", "pm.test(\"Response time is less than 1000ms\", function () {", " pm.expect(pm.response.responseTime).to.be.below(1000);", "});", "", "// 检查响应结构", "pm.test(\"Response has correct async structure\", function () {", " var jsonData = pm.response.json();", " pm.expect(jsonData).to.have.property('code');", " pm.expect(jsonData).to.have.property('data');", " pm.expect(jsonData.data).to.have.property('executionId');", " pm.expect(jsonData.data).to.have.property('auditTaskId');", " pm.expect(jsonData.data).to.have.property('status');", "});", "", "// 检查状态", "pm.test(\"Status should be pending_audit\", function () {", " var jsonData = pm.response.json();", " pm.expect(jsonData.data.status).to.equal('pending_audit');", "});", "", "// 保存executionId用于后续查询", "if (pm.response.code === 200) {", " var jsonData = pm.response.json();", " pm.collectionVariables.set('executionId', jsonData.data.executionId);", " console.log('已保存executionId: ' + jsonData.data.executionId);", "}", "", "// 记录响应时间", "console.log('异步API响应时间: ' + pm.response.responseTime + 'ms');" ], "type": "text/javascript" } } ], "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" }, { "key": "Authorization", "value": "{{authorization}}" } ], "body": { "mode": "raw", "raw": "{\n \"imageUrl\": \"{{imageUrl}}\"\n}" }, "url": { "raw": "{{baseUrl}}/enhanced/templates/code/photo_restore_v1/execute", "host": ["{{baseUrl}}"], "path": ["enhanced", "templates", "code", "photo_restore_v1", "execute"] }, "description": "测试新的异步模板执行API - 提交任务" } }, { "name": "3. 查询执行状态", "event": [ { "listen": "test", "script": { "exec": [ "// 检查响应状态", "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "// 检查响应结构", "pm.test(\"Response has correct status structure\", function () {", " var jsonData = pm.response.json();", " pm.expect(jsonData).to.have.property('data');", " pm.expect(jsonData.data).to.have.property('executionId');", " pm.expect(jsonData.data).to.have.property('status');", " pm.expect(jsonData.data).to.have.property('statusDescription');", "});", "", "// 显示当前状态", "if (pm.response.code === 200) {", " var jsonData = pm.response.json();", " console.log('当前状态: ' + jsonData.data.status);", " console.log('状态描述: ' + jsonData.data.statusDescription);", " ", " if (jsonData.data.outputUrl) {", " console.log('输出地址: ' + jsonData.data.outputUrl);", " }", "}" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [ { "key": "Authorization", "value": "{{authorization}}" } ], "url": { "raw": "{{baseUrl}}/enhanced/templates/{{executionId}}/status", "host": ["{{baseUrl}}"], "path": ["enhanced", "templates", "{{executionId}}", "status"] }, "description": "查询异步任务的执行状态。需要先运行步骤2获取executionId。" } }, { "name": "4. 获取模板列表", "event": [ { "listen": "test", "script": { "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", "});", "", "pm.test(\"Response is array\", function () {", " var jsonData = pm.response.json();", " pm.expect(jsonData.data).to.be.an('array');", "});", "", "// 显示可用模板", "if (pm.response.code === 200) {", " var jsonData = pm.response.json();", " console.log('可用模板数量: ' + jsonData.data.length);", " jsonData.data.forEach(function(template) {", " console.log('- ' + template.code + ': ' + template.name);", " });", "}" ], "type": "text/javascript" } } ], "request": { "method": "GET", "header": [ { "key": "Authorization", "value": "{{authorization}}" } ], "url": { "raw": "{{baseUrl}}/api/v1/templates", "host": ["{{baseUrl}}"], "path": ["api", "v1", "templates"] }, "description": "获取所有可用的模板列表" } }, { "name": "5. 错误测试 - 无效图片URL", "event": [ { "listen": "test", "script": { "exec": [ "// 应该返回错误状态", "pm.test(\"Should return error status\", function () {", " pm.expect(pm.response.code).to.be.oneOf([400, 403, 422]);", "});", "", "// 检查错误信息", "pm.test(\"Should have error message\", function () {", " var jsonData = pm.response.json();", " pm.expect(jsonData).to.have.property('message');", "});", "", "console.log('错误测试通过: 无效图片URL正确返回错误');" ], "type": "text/javascript" } } ], "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" }, { "key": "Authorization", "value": "{{authorization}}" } ], "body": { "mode": "raw", "raw": "{\n \"imageUrl\": \"https://invalid-domain.com/nonexistent.jpg\"\n}" }, "url": { "raw": "{{baseUrl}}/enhanced/templates/code/photo_restore_v1/execute", "host": ["{{baseUrl}}"], "path": ["enhanced", "templates", "code", "photo_restore_v1", "execute"] }, "description": "测试无效图片URL的错误处理" } }, { "name": "6. 错误测试 - 无效模板代码", "event": [ { "listen": "test", "script": { "exec": [ "// 应该返回404错误", "pm.test(\"Should return 404 status\", function () {", " pm.response.to.have.status(404);", "});", "", "console.log('错误测试通过: 无效模板代码正确返回404错误');" ], "type": "text/javascript" } } ], "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" }, { "key": "Authorization", "value": "{{authorization}}" } ], "body": { "mode": "raw", "raw": "{\n \"imageUrl\": \"{{imageUrl}}\"\n}" }, "url": { "raw": "{{baseUrl}}/enhanced/templates/code/nonexistent_template/execute", "host": ["{{baseUrl}}"], "path": ["enhanced", "templates", "code", "nonexistent_template", "execute"] }, "description": "测试无效模板代码的错误处理" } } ] }