From 0d04724fd1d6f4186d0f211a128b8ed059be1e59 Mon Sep 17 00:00:00 2001 From: taohebin Date: Fri, 14 Jun 2024 17:08:16 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0request=20Cookie?= =?UTF-8?q?=E8=BF=87=E6=9C=9F=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/request/request.test.js | 23 ++++++++++++++++++++++- pages/API/request/request.uvue | 22 ++++++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/pages/API/request/request.test.js b/pages/API/request/request.test.js index 336d8ac3..0b709f9d 100644 --- a/pages/API/request/request.test.js +++ b/pages/API/request/request.test.js @@ -117,7 +117,28 @@ describe('ExtApi-Request', () => { await page.waitFor(2000); res = await page.data('jest_result'); expect(res).toBe(true) - }); + }); + it('Check Set Cookie Expires', async () => { + await page.callMethod('jest_set_cookie_expires') + await page.waitFor(2000); + res = await page.data('jest_result_data'); + console.log("request expires cookie data :", res); + res = await page.data('jest_result'); + expect(res).toBe(true) + await page.setData({ + jest_result: false, + jest_result_data: "", + data: null, + header: null + }) + await page.waitFor(5000); + await page.callMethod('jest_cookie_request', false) + await page.waitFor(2000); + res = await page.data('jest_result_data'); + console.log("verify request data :", res); + res = await page.data('jest_result'); + expect(res).toBe(true) + }); it('Check Get With Data', async () => { res = await page.callMethod('jest_get_with_data') await page.waitFor(2000); diff --git a/pages/API/request/request.uvue b/pages/API/request/request.uvue index 190cec7e..65b26d92 100644 --- a/pages/API/request/request.uvue +++ b/pages/API/request/request.uvue @@ -141,7 +141,8 @@ "/api/http/contentType/xWwwFormUrlencoded", ], //自动化测试例专用 - jest_result: false + jest_result: false, + jest_result_data: "" } }, onLoad() { @@ -257,6 +258,22 @@ this.jest_result = false; }, }); + }, + jest_set_cookie_expires(){ + uni.request({ + url: this.host + "/api/http/header/setCookie?expires=5", + method: "GET", + timeout: 6000, + sslVerify: false, + withCredentials: false, + firstIpv4: false, + success: () => { + this.jest_cookie_request(true) + }, + fail: () => { + this.jest_result = false; + }, + }); }, jest_delete_cookie() { uni.request({ @@ -284,7 +301,8 @@ firstIpv4: false, success: (res) => { const requestCookie = (res.data as UTSJSONObject).getJSON("data")?.getAny("requestCookie") - console.log("requestCookie ", requestCookie); + console.log("requestCookie ", requestCookie); + this.jest_result_data = JSON.stringify(requestCookie) if (requestCookie instanceof Array) { this.jest_result = needCookie ? requestCookie.length > 0 : requestCookie.length == 0 } else { -- GitLab