diff --git a/pages/API/download-file/download-file.test.js b/pages/API/download-file/download-file.test.js index 3f15f2753ffee7cbd3ed17fc50a8ce2d80e78690..928f5fbe1329c0802e412b03c3b765c20251232c 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 d4b9f46528ea4c6fa7db8a430dc92fb4574b731b..b7478faccc26950302b81296fdd5b310b64cae7c 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 56f73f062bc53dcfa0fd42aafc95a8ffe7c4019a..8ea7287e8e7ce0b80adc1014051d8783a46bfcb5 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 5355dbefe1b7c334327946303aaaa983146199aa..8ac541256617b38b7f31dad64f4266084a466aed 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 +