From 311a27523f88c175eb10a756c2aff4de09e70e26 Mon Sep 17 00:00:00 2001 From: Leon <147289645+LeoninCS@users.noreply.github.com> Date: Fri, 5 Dec 2025 14:04:57 +0800 Subject: [PATCH] test: postman json of auth(login and logout) --- test/auth.json | 128 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 test/auth.json diff --git a/test/auth.json b/test/auth.json new file mode 100644 index 0000000..7d4be42 --- /dev/null +++ b/test/auth.json @@ -0,0 +1,128 @@ +{ + "info": { + "_postman_id": "2a6b02fb-7ab2-4f4c-a1c6-6e19e7d9f2ba", + "name": "feedsystem auth flow", + "description": "使用 Postman 验证 /auth/login 与 /auth/logout 接口。先运行 Login 请求以保存 token,再运行 Logout 请求;Logout 会自动把 token 放到 Authorization 头里。", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Login", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"username\": \"{{username}}\",\n \"password\": \"{{password}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/auth/login", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "auth", + "login" + ] + } + }, + "event": [ + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "pm.test(\"登录成功\", function () {", + " pm.response.to.have.status(200);", + " var data = pm.response.json();", + " pm.expect(data.token).to.exist;", + " pm.collectionVariables.set(\"jwt_token\", data.token);", + "});" + ] + } + } + ] + }, + { + "name": "Logout", + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "if (!pm.collectionVariables.get(\"jwt_token\")) {", + " throw new Error(\"请先运行 Login 请求以获取 token\");", + "}" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "pm.test(\"登出成功\", function () {", + " pm.response.to.have.status(200);", + "});" + ] + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Authorization", + "value": "Bearer {{jwt_token}}" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"id\": {{userId}}\n}" + }, + "url": { + "raw": "{{baseUrl}}/auth/logout", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "auth", + "logout" + ] + } + } + } + ], + "variable": [ + { + "key": "baseUrl", + "value": "http://localhost:8080" + }, + { + "key": "username", + "value": "demo" + }, + { + "key": "password", + "value": "demo123" + }, + { + "key": "userId", + "value": "1" + }, + { + "key": "jwt_token", + "value": "" + } + ] +}