diff --git a/pages/API/request/request.test.js b/pages/API/request/request.test.js index db18e65c23d44f8fc3a6d8af060bc4437e716f53..e4157b0aff1df2ec17ae2142ceb4e9d5e77731c9 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 b56dcc13b4d65f69c95fe675cd0d807748236d73..93e03d363cc7d685e8ea4fe720f107d99f07548a 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 +