test(expiry): 完成 #32 接口集成测试资产

This commit is contained in:
root
2026-03-04 18:37:45 +08:00
parent 6c303abd58
commit 3668b10be3
4 changed files with 314 additions and 0 deletions
@@ -0,0 +1,170 @@
{
"info": {
"_postman_id": "3f8f9f2a-8b2f-4cc0-91df-0c8d7a03b101",
"name": "Expiry API Integration",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"description": "保质期提醒小程序后端接口集成测试集合"
},
"item": [
{
"name": "Auth - Login",
"request": {
"method": "POST",
"header": [
{ "key": "Content-Type", "value": "application/json" }
],
"body": {
"mode": "raw",
"raw": "{\n \"mini_program_id\": {{mini_program_id}},\n \"code\": \"{{wx_code}}\"\n}"
},
"url": {
"raw": "{{base_url}}/api/v1/auth/login",
"host": ["{{base_url}}"],
"path": ["api", "v1", "auth", "login"]
}
},
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test('login status 200', function () {",
" pm.response.to.have.status(200);",
"});",
"const json = pm.response.json();",
"pm.test('login business code 200', function () {",
" pm.expect(json.code).to.eql(200);",
"});",
"if (json.data && json.data.session_key) {",
" pm.environment.set('token', json.data.session_key);",
"}"
],
"type": "text/javascript"
}
}
]
},
{
"name": "Expiry - Create Item",
"request": {
"method": "POST",
"header": [
{ "key": "Content-Type", "value": "application/json" },
{ "key": "Authorization", "value": "Bearer {{token}}" }
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"自动化牛奶\",\n \"category\": \"food\",\n \"expiry_date\": \"2030-12-31\",\n \"quantity\": 2,\n \"location\": \"冰箱\"\n}"
},
"url": {
"raw": "{{base_url}}/api/expiry/items",
"host": ["{{base_url}}"],
"path": ["api", "expiry", "items"]
}
},
"event": [
{
"listen": "test",
"script": {
"exec": [
"const json = pm.response.json();",
"pm.test('create success', function () {",
" pm.expect(pm.response.code).to.eql(200);",
" pm.expect(json.code).to.eql(0);",
"});",
"if (json.data && json.data.id) {",
" pm.environment.set('item_id', json.data.id);",
"}"
],
"type": "text/javascript"
}
}
]
},
{
"name": "Expiry - Get Items",
"request": {
"method": "GET",
"header": [
{ "key": "Authorization", "value": "Bearer {{token}}" }
],
"url": {
"raw": "{{base_url}}/api/expiry/items?status=all&page=1&page_size=20",
"host": ["{{base_url}}"],
"path": ["api", "expiry", "items"],
"query": [
{ "key": "status", "value": "all" },
{ "key": "page", "value": "1" },
{ "key": "page_size", "value": "20" }
]
}
}
},
{
"name": "Expiry - Get Summary",
"request": {
"method": "GET",
"header": [
{ "key": "Authorization", "value": "Bearer {{token}}" }
],
"url": {
"raw": "{{base_url}}/api/expiry/summary",
"host": ["{{base_url}}"],
"path": ["api", "expiry", "summary"]
}
}
},
{
"name": "Expiry - Update Status Used",
"request": {
"method": "POST",
"header": [
{ "key": "Content-Type", "value": "application/json" },
{ "key": "Authorization", "value": "Bearer {{token}}" }
],
"body": {
"mode": "raw",
"raw": "{\n \"status\": \"used\"\n}"
},
"url": {
"raw": "{{base_url}}/api/expiry/items/{{item_id}}/status",
"host": ["{{base_url}}"],
"path": ["api", "expiry", "items", "{{item_id}}", "status"]
}
}
},
{
"name": "Expiry - Settings Get",
"request": {
"method": "GET",
"header": [
{ "key": "Authorization", "value": "Bearer {{token}}" }
],
"url": {
"raw": "{{base_url}}/api/expiry/settings",
"host": ["{{base_url}}"],
"path": ["api", "expiry", "settings"]
}
}
},
{
"name": "Expiry - Settings Update",
"request": {
"method": "POST",
"header": [
{ "key": "Content-Type", "value": "application/json" },
{ "key": "Authorization", "value": "Bearer {{token}}" }
],
"body": {
"mode": "raw",
"raw": "{\n \"remind_days\": [10, 5, 1]\n}"
},
"url": {
"raw": "{{base_url}}/api/expiry/settings",
"host": ["{{base_url}}"],
"path": ["api", "expiry", "settings"]
}
}
}
]
}