From cb0b098c5aeb54ce70db0e130423dd3aac1ad934 Mon Sep 17 00:00:00 2001 From: taohebin Date: Mon, 25 Dec 2023 18:09:38 +0800 Subject: [PATCH] =?UTF-8?q?test:=20request=E5=A2=9E=E5=8A=A0cookie?= =?UTF-8?q?=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/request/request.test.js | 13 +++++++ pages/API/request/request.uvue | 61 +++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/pages/API/request/request.test.js b/pages/API/request/request.test.js index db18e65c..e4157b0a 100644 --- a/pages/API/request/request.test.js +++ b/pages/API/request/request.test.js @@ -75,5 +75,18 @@ describe('ExtApi-Request', () => { }); it('Check HEAD', async () => { await request(page, 'HEAD'); + }); + + it('Check Set Cookie', async () => { + res = await page.callMethod('jest_set_cookie') + await page.waitFor(500); + res = await page.data('jest_result'); + expect(res).toBe(true) + }); + it('Check Delete Cookie', async () => { + res = await page.callMethod('jest_delete_cookie') + await page.waitFor(1000); + res = await page.data('jest_result'); + expect(res).toBe(true) }); }); diff --git a/pages/API/request/request.uvue b/pages/API/request/request.uvue index b56dcc13..93e03d36 100644 --- a/pages/API/request/request.uvue +++ b/pages/API/request/request.uvue @@ -188,7 +188,8 @@ withCredentials: false, firstIpv4: false, success: (res) => { - console.log('request success', JSON.stringify(res.data)) + console.log('request success', JSON.stringify(res.data)) + console.log('request success header is :', JSON.stringify(res.header)) uni.showToast({ title: '请求成功', icon: 'success', @@ -229,7 +230,61 @@ this.jest_result = false; }, }); - } + }, + jest_set_cookie() { + uni.request({ + url: this.host + "/api/http/header/setCookie", + 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({ + url: this.host + "/api/http/header/deleteCookie", + method: "GET", + timeout: 6000, + sslVerify: false, + withCredentials: false, + firstIpv4: false, + success: () => { + this.jest_cookie_request(false) + }, + fail: () => { + this.jest_result = false; + }, + }); + }, + jest_cookie_request(needCookie: boolean) { + uni.request({ + url: this.host + "/api/http/header/requestCookie", + method: "GET", + timeout: 6000, + sslVerify: false, + withCredentials: false, + firstIpv4: false, + success: (res) => { + const requestCookie = (res.data as UTSJSONObject).getJSON("data")?.getAny("requestCookie") + console.log("requestCookie ", requestCookie); + if(requestCookie instanceof Array){ + this.jest_result = needCookie ? requestCookie.length > 0 : requestCookie.length == 0 + }else{ + this.jest_result = needCookie ? (requestCookie as UTSJSONObject).toMap().size > 0 : (requestCookie as UTSJSONObject).toMap().size == 0 + } + }, + fail: () => { + this.jest_result = false; + }, + }); + }, } } - \ No newline at end of file + -- GitLab