From 2f781c49edd7dcac9ecff758a054164eff0c72ec Mon Sep 17 00:00:00 2001 From: taohebin Date: Tue, 2 Jan 2024 18:44:33 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E8=A1=A5=E5=85=85=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E7=9A=84cookie=E6=B5=8B=E8=AF=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/download-file/download-file.test.js | 18 ++++++ pages/API/download-file/download-file.uvue | 45 ++++++++++++++ pages/API/upload-file/upload-file.test.js | 19 ++++++ pages/API/upload-file/upload-file.uvue | 58 ++++++++++++++++++- 4 files changed, 138 insertions(+), 2 deletions(-) diff --git a/pages/API/download-file/download-file.test.js b/pages/API/download-file/download-file.test.js index 3f15f275..928f5fbe 100644 --- a/pages/API/download-file/download-file.test.js +++ b/pages/API/download-file/download-file.test.js @@ -10,9 +10,27 @@ describe('ExtApi-DownloadFile', () => { await page.callMethod('jest_downloadFile'); await page.waitFor(1000); res = await page.data('jest_result'); + }); + + beforeEach(async () => { + await page.setData({ + jest_result: false + }) }); it('Check ', async () => { expect(res).toBe(true); + }); + it('Check Set Cookie', async () => { + res = await page.callMethod('jest_set_cookie') + await page.waitFor(1000); + 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/download-file/download-file.uvue b/pages/API/download-file/download-file.uvue index d4b9f465..b7478fac 100644 --- a/pages/API/download-file/download-file.uvue +++ b/pages/API/download-file/download-file.uvue @@ -69,6 +69,51 @@ this.jest_result = false } }); + }, + + jest_set_cookie(){ + uni.request({ + url: "http://request.dcloud.net.cn/api/http/header/setCookie", + method: "GET", + timeout: 6000, + sslVerify: false, + withCredentials: false, + firstIpv4: false, + success: () => { + this.jest_cookie_download(true) + }, + fail: () => { + this.jest_result = false; + }, + }); + }, + + jest_delete_cookie(){ + uni.request({ + url: "http://request.dcloud.net.cn/api/http/header/deleteCookie", + method: "GET", + timeout: 6000, + sslVerify: false, + withCredentials: false, + firstIpv4: false, + success: () => { + this.jest_cookie_download(false) + }, + fail: () => { + this.jest_result = false; + }, + }); + }, + jest_cookie_download(needCookie: boolean){ + uni.downloadFile({ + url: "http://request.dcloud.net.cn/api/http/header/download", + success: () => { + this.jest_result = needCookie ? true : false; + }, + fail: () => { + this.jest_result = needCookie ? false : true; + } + }); } } } diff --git a/pages/API/upload-file/upload-file.test.js b/pages/API/upload-file/upload-file.test.js index 56f73f06..8ea7287e 100644 --- a/pages/API/upload-file/upload-file.test.js +++ b/pages/API/upload-file/upload-file.test.js @@ -10,9 +10,28 @@ describe('ExtApi-UploadFile', () => { await page.callMethod('jest_uploadFile'); await page.waitFor(1000); res = await page.data('jest_result'); + }); + + beforeEach(async () => { + await page.setData({ + jest_result: false + }) }); it('Check ', async () => { expect(res).toBe(true); + }); + + it('Check Set Cookie', async () => { + res = await page.callMethod('jest_set_cookie') + await page.waitFor(1000); + 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/upload-file/upload-file.uvue b/pages/API/upload-file/upload-file.uvue index 5355dbef..8ac54125 100644 --- a/pages/API/upload-file/upload-file.uvue +++ b/pages/API/upload-file/upload-file.uvue @@ -94,7 +94,61 @@ this.jest_result = false; }, }) - } + }, + jest_set_cookie(){ + uni.request({ + url: "http://request.dcloud.net.cn/api/http/header/setCookie", + method: "GET", + timeout: 6000, + sslVerify: false, + withCredentials: false, + firstIpv4: false, + success: () => { + this.jest_cookie_upload(true) + }, + fail: () => { + this.jest_result = false; + }, + }); + }, + + jest_delete_cookie(){ + uni.request({ + url: "http://request.dcloud.net.cn/api/http/header/deleteCookie", + method: "GET", + timeout: 6000, + sslVerify: false, + withCredentials: false, + firstIpv4: false, + success: () => { + this.jest_cookie_upload(false) + }, + fail: () => { + this.jest_result = false; + }, + }); + }, + jest_cookie_upload(needCookie: boolean){ + const imageSrc = "/static/uni.png"; + this.task = uni.uploadFile({ + url: 'http://request.dcloud.net.cn/api/http/header/upload', + filePath: imageSrc, + name: 'file', + success: (res:UploadFileSuccess) => { + const data = JSON.parseObject(res.data) + const errCode = data?.getNumber("errCode") + if(errCode != null && errCode == 1000){ + this.jest_result = needCookie ? false : true; + }else{ + this.jest_result = needCookie ? true : false; + } + }, + fail: () => { + this.jest_result = false; + }, + }) + } + } } @@ -119,4 +173,4 @@ font-size: 38rpx; color: #808080; } - \ No newline at end of file + -- GitLab