提交 2f781c49 编写于 作者: taohebin@dcloud.io's avatar taohebin@dcloud.io

update: 补充上传下载的cookie测试例

上级 11feed5f
...@@ -10,9 +10,27 @@ describe('ExtApi-DownloadFile', () => { ...@@ -10,9 +10,27 @@ describe('ExtApi-DownloadFile', () => {
await page.callMethod('jest_downloadFile'); await page.callMethod('jest_downloadFile');
await page.waitFor(1000); await page.waitFor(1000);
res = await page.data('jest_result'); res = await page.data('jest_result');
});
beforeEach(async () => {
await page.setData({
jest_result: false
})
}); });
it('Check ', async () => { it('Check ', async () => {
expect(res).toBe(true); 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)
}); });
}); });
...@@ -69,6 +69,51 @@ ...@@ -69,6 +69,51 @@
this.jest_result = false 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;
}
});
} }
} }
} }
......
...@@ -10,9 +10,28 @@ describe('ExtApi-UploadFile', () => { ...@@ -10,9 +10,28 @@ describe('ExtApi-UploadFile', () => {
await page.callMethod('jest_uploadFile'); await page.callMethod('jest_uploadFile');
await page.waitFor(1000); await page.waitFor(1000);
res = await page.data('jest_result'); res = await page.data('jest_result');
});
beforeEach(async () => {
await page.setData({
jest_result: false
})
}); });
it('Check ', async () => { it('Check ', async () => {
expect(res).toBe(true); 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)
}); });
}); });
...@@ -94,7 +94,61 @@ ...@@ -94,7 +94,61 @@
this.jest_result = false; 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;
},
})
}
} }
} }
</script> </script>
...@@ -119,4 +173,4 @@ ...@@ -119,4 +173,4 @@
font-size: 38rpx; font-size: 38rpx;
color: #808080; color: #808080;
} }
</style> </style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册