diff --git a/pages/clientDB/clientDB-api/clientDB-api.test.js b/pages/clientDB/clientDB-api/clientDB-api.test.js index 10d6f882204a07b6e701e7d91f023a589944dc63..7438bc16abb4c415202a189aa119ce1939f140f9 100644 --- a/pages/clientDB/clientDB-api/clientDB-api.test.js +++ b/pages/clientDB/clientDB-api/clientDB-api.test.js @@ -4,19 +4,14 @@ describe('pages/clientDB/clientDB-api/clientDB-api.nvue', () => { beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch('/pages/clientDB/clientDB-api/clientDB-api') - if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") { - await page.waitFor(1000) - } - if (process.env.UNI_PLATFORM === "mp-weixin") { - await page.waitFor(1000);//微信等待 - } + await page.waitFor(1000) page = await program.currentPage() }) - beforeEach(async()=>{ - jest.setTimeout(30000) - return false - }) + // beforeEach(async()=>{ + // jest.setTimeout(30000) + // return false + // }) it('查图书book表的数据', async () => { expect.assertions(1); @@ -36,11 +31,9 @@ describe('pages/clientDB/clientDB-api/clientDB-api.nvue', () => { const numBox1 = await page.$('.num-box1') const pageSize = await numBox1.property('value') - console.log("pageSize: ",pageSize); //获取当前页 const numBox2 = await page.$('.num-box2') const pageCurrent = await numBox2.property('value') - console.log("pageCurrent: ",pageCurrent); if (pageSize === 1 && pageCurrent == 2) { const orderData = await page.callMethod('getPageData', 'order') diff --git a/pages/clientDB/clientDB-api/clientDB-api.vue b/pages/clientDB/clientDB-api/clientDB-api.vue index 47e6c374f9ac8cc9e9829b67a58e151d9d91306c..d0f5703b1e7671ff7e9fe4899675b8428cadae63 100644 --- a/pages/clientDB/clientDB-api/clientDB-api.vue +++ b/pages/clientDB/clientDB-api/clientDB-api.vue @@ -222,21 +222,24 @@ uni.hideLoading() } }, - getData(tableName) { + async getData(tableName) { console.log(tableName); uni.showLoading({ mask: true }); // 客户端联表查询 - db.collection(tableName) + return await db.collection(tableName) .get() .then(res => { this.$refs.alertCode.open(res.result) + return res.result.data }).catch(err => { console.error(err) + return err }) .finally((e) => { uni.hideLoading() + console.log(e); }) }, async getOrderByGetTemp() { @@ -248,107 +251,119 @@ uni.hideLoading() this.$refs.alertCode.open(res.result) }, - getOrder() { + async getOrder() { //直接关联多个表为虚拟表再进行查询。仅数据表字段内容较少时使用,否者将查询超时 uni.showLoading({mask: true}); // 客户端联表查询 - db.collection('order,book') // 注意collection方法内需要传入所有用到的表名,用逗号分隔,主表需要放在第一位 + return await db.collection('order,book') // 注意collection方法内需要传入所有用到的表名,用逗号分隔,主表需要放在第一位 //.where('book_id.title == "三国演义"') // 查询order表内书名为“三国演义”的订单 .field('book_id{title,author} as books_info,quantity') // 这里联表查询book表返回book表内的title、book表内的author、order表内的quantity .get() .then(res => { this.$refs.alertCode.open(res.result) + return res.result.data }).catch(err => { console.error(err) + return err }).finally(() => { uni.hideLoading() }) }, - getOneBook() { + async getOneBook() { uni.showLoading({ mask: true }); // 客户端联表查询 - db.collection('book') + return await db.collection('book') .get({ getOne: true }) .then(res => { this.$refs.alertCode.open(res.result) + return res.result.data }).catch(err => { console.error(err) + return err }).finally(() => { uni.hideLoading() }) }, - getBookTitle() { + async getBookTitle() { uni.showLoading({ mask: true }); // 客户端联表查询 - db.collection('book') + return await db.collection('book') .field('title') .get() .then(res => { this.$refs.alertCode.open(res.result) + return res.result.data }).catch(err => { console.error(err) + return err }).finally(() => { uni.hideLoading() }) }, - getBookAs() { + async getBookAs() { uni.showLoading({ mask: true }); // 客户端联表查询 - db.collection('book') + return await db.collection('book') .field('title,author as book_author') .get() .then(res => { this.$refs.alertCode.open(res.result) + return res.result.data }).catch(err => { console.error(err) + return err }).finally(() => { uni.hideLoading() }) }, - getOrderOrderBy(str) { + async getOrderOrderBy(str) { uni.showLoading({ mask: true }); - db.collection('order') + return await db.collection('order') .orderBy(str) .get() .then(res => { this.$refs.alertCode.open(res.result) + return res.result.data }).catch(err => { console.error(err) + return err }).finally(() => { uni.hideLoading() }) }, - getBookHasCount() { + async getBookHasCount() { uni.showLoading({ mask: true }); - db.collection('book') + return await db.collection('book') .get({ "getCount": true }) .then(res => { this.$refs.alertCode.open(res.result) + return res.result }).catch(err => { console.error(err) + return err }).finally(() => { uni.hideLoading() }) }, - getTreeFn() { + async getTreeFn() { uni.showLoading({ mask: true }); - db.collection("department").get({ + return await db.collection("department").get({ getTree: { limitLevel: 10, // 最大查询层级(不包含当前层级),可以省略默认10级,最大15,最小1 // startWith: "parent_code==''" // 第一层级条件,此初始条件可以省略,不传startWith时默认从最顶级开始查询 @@ -358,11 +373,13 @@ console.log("res: ",res); const resdata = res.result.data this.$refs.alertCode.open(resdata) + return resdata }).catch((err) => { uni.showModal({ content: err.message || '请求服务失败', showCancel: false }) + return err }).finally(() => { uni.hideLoading() }) @@ -378,6 +395,7 @@ console.log(res); this.$refs.alertCode.open(res.result.data) uni.hideLoading() + return res.result.data } } } diff --git a/pages/clientDB/clientDB.test.js b/pages/clientDB/clientDB.test.js index 873f34c4f8e4727bc98cb56e4c3be38a3ede1c8a..64ebe2ec6c462cc3736ced74401fc2fac3914abf 100644 --- a/pages/clientDB/clientDB.test.js +++ b/pages/clientDB/clientDB.test.js @@ -3,14 +3,7 @@ describe('pages/clientDB/clientDB.vue', () => { beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch('/pages/clientDB/clientDB') - - if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus") { - await page.waitFor(1000) - } - if (process.env.UNI_PLATFORM === "mp-weixin") { - await page.waitFor(1000) - } - + await page.waitFor(1000) page = await program.currentPage() }) diff --git a/pages/clientDB/demo/demo.test.js b/pages/clientDB/demo/demo.test.js index a9ed52f2eab92a85edc8b7575a34b7298afa568a..e8bd9eda95491875839c973af8aa1e6522ca44cf 100644 --- a/pages/clientDB/demo/demo.test.js +++ b/pages/clientDB/demo/demo.test.js @@ -4,14 +4,8 @@ describe('pages/clientDB/demo/demo.vue', () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch( '/pages/clientDB/demo/demo') - if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") { - await page.waitFor(1000) - } - if (process.env.UNI_PLATFORM === "mp-weixin") { - await page.waitFor(1000);//微信等待 - } + await page.waitFor(1000) page = await program.currentPage() - // console.log("page-------------: ",page); }) beforeEach(async()=>{ @@ -20,7 +14,6 @@ describe('pages/clientDB/demo/demo.vue', () => { }) - it('未登陆', async () => { const perPage = await page.$('.page') //底部角色控制条 @@ -91,7 +84,7 @@ describe('pages/clientDB/demo/demo.vue', () => { const auditorWrite = await page.callMethod('submitComment', '我是审核员11') const audId = auditorWrite.id expect(audId).not.toBeUndefined(); - await page.waitFor(1000) + await page.waitFor(800) // 审核一条为通过 await page.callMethod('updateState', { @@ -101,7 +94,7 @@ describe('pages/clientDB/demo/demo.vue', () => { }, audId ) - await page.waitFor(1000) + await page.waitFor(800) //审核员更改留言 const setUid = await page.setData({ @@ -110,7 +103,7 @@ describe('pages/clientDB/demo/demo.vue', () => { const auditorUpdate = await page.callMethod('updateComment', "我是审核员123" ) - await page.waitFor(1000) + await page.waitFor(800) } diff --git a/pages/clientDB/demo/demo.vue b/pages/clientDB/demo/demo.vue index 8f2047fc5ce16cc55e7cc21bc3709471de7e80f1..8f60da957244645e330292d197c344289da2d680 100644 --- a/pages/clientDB/demo/demo.vue +++ b/pages/clientDB/demo/demo.vue @@ -129,7 +129,6 @@ console.log("this.currentRole: ", this.currentRole); }, async getNoticeData() { - console.log('111111111111'); let res = await db.action('add_view_count') .collection('notice') .field('data,_id,update_time,view_count') @@ -146,12 +145,12 @@ this.$refs.upDataDialog.open() } }, - updateState(e, _id) { + async updateState(e, _id) { console.log(e.detail.value, _id); uni.showLoading({ mask: true }); - db.collection('comment') + return await db.collection('comment') .doc(_id) .update({ "state": e.detail.value / 1 @@ -163,11 +162,14 @@ duration: 3000 }); console.log(code, message); + return message }).catch(({code,message}) => { console.log(code, message); + return message }).finally(e => { uni.hideLoading() this.$refs.upDataDialog.close() + return e }) }, async updateComment(text) { @@ -185,7 +187,7 @@ uni.showLoading({ mask: true }); - await this.$refs.udb.update(this.activeNoticeId, {text}, { + return await this.$refs.udb.update(this.activeNoticeId, {text}, { action: "up_comment", toastTitle: '修改成功', // toast提示语 success: (res) => { // 更新成功后的回调 @@ -203,10 +205,12 @@ } } }) + return message }, fail: (err) => { // 更新失败后的回调 console.log("err: ",err); const {message} = err + return message }, complete: () => { // 完成后的回调 uni.hideLoading() @@ -224,11 +228,12 @@ return false } this.$refs.dialog.close() - await db.collection('comment').add({ + return await db.collection('comment').add({ text }).then(res => { console.log(res); this.getNewData() + return res.result }).catch(({ code, message @@ -246,6 +251,7 @@ }); } console.log(code, message); + return message }) }, getNewData() { diff --git a/pages/clientDB/permission-demo/permission-demo.test.js b/pages/clientDB/permission-demo/permission-demo.test.js index 0bf6beeabdbc5a063accb7cb1b1979e067e51bfe..a10412f4028cf8f4a78af05fd7e11e8e0cd04320 100644 --- a/pages/clientDB/permission-demo/permission-demo.test.js +++ b/pages/clientDB/permission-demo/permission-demo.test.js @@ -13,10 +13,10 @@ describe('pages/clientDB/permission-demo/permission-demo.vue', () => { page = await program.currentPage() }) - beforeEach(async()=>{ - jest.setTimeout(30000) - return false - }) + // beforeEach(async()=>{ + // jest.setTimeout(30000) + // return false + // }) it('未登陆', async () => { diff --git a/pages/clientDB/permission-demo/readme.test.js b/pages/clientDB/permission-demo/readme.test.js index e3c46967cbd32f9c8ddecfe3505a1171e7f7efac..cf4ae796fc992d9f8a7725a711e34cc2ee41bfcc 100644 --- a/pages/clientDB/permission-demo/readme.test.js +++ b/pages/clientDB/permission-demo/readme.test.js @@ -5,19 +5,14 @@ describe('pages/clientDB/permission-demo/readme.vue', () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch( '/pages/clientDB/permission-demo/readme') - if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus" ) { - await page.waitFor(1000) - } - if (process.env.UNI_PLATFORM === "mp-weixin") { - await page.waitFor(1000);//微信等待 - } + await page.waitFor(1000) // page = await program.currentPage() }) - beforeEach(async()=>{ - jest.setTimeout(30000) - return false - }) + // beforeEach(async()=>{ + // jest.setTimeout(30000) + // return false + // }) it('用户', async () => { @@ -199,7 +194,7 @@ describe('pages/clientDB/permission-demo/readme.vue', () => { const auditorRole = await page.data('currentRole') return auditorRole == 'auditor' }) - console.log(auditor); + // console.log(auditor); if(auditor){ @@ -330,9 +325,6 @@ describe('pages/clientDB/permission-demo/readme.vue', () => { } - - }) - }) \ No newline at end of file diff --git a/pages/clientDB/permission-demo/readme.vue b/pages/clientDB/permission-demo/readme.vue index 12b5ae5d6b70a46e5ba40fa2e12bb7578b8228ee..411132459b5aad7cdaa3cac00c55bdeef4294800 100644 --- a/pages/clientDB/permission-demo/readme.vue +++ b/pages/clientDB/permission-demo/readme.vue @@ -221,9 +221,9 @@ urls:[url] }) }, - addFn(){ + async addFn(){ uni.showLoading({mask:true}) - ptDb.add({ + return await ptDb.add({ nickname:"默认昵称", username:"默认姓名", phone:"18888888888" @@ -234,6 +234,7 @@ showCancel: false, confirmText:"知道了" }); + return e }).catch(err=>{ console.log(err); uni.showModal({ @@ -242,19 +243,21 @@ showCancel: false, confirmText:"知道了" }); + return err }).finally(() => { uni.hideLoading() }) }, - removeFn(){ + async removeFn(){ uni.showLoading({mask:true}) - ptDb.remove().then(e=>{ + return await ptDb.remove().then(e=>{ console.log(e,"123"); uni.showModal({ content: JSON.stringify(e.result), showCancel: false, confirmText:"知道了" }); + return e }).catch(err=>{ console.log(JSON.stringify(err)); uni.showModal({ @@ -263,6 +266,7 @@ showCancel: false, confirmText:"知道了" }); + return err }).finally(() => { uni.hideLoading() }) @@ -270,10 +274,10 @@ updateNickname(self){ }, - updateFn(data,where={}){ + async updateFn(data,where={}){ console.log(data); uni.showLoading({mask:true}) - ptDb.where(where).update(data) + return await ptDb.where(where).update(data) .then(e=>{ console.log(e); uni.showModal({ @@ -281,6 +285,7 @@ showCancel: false, confirmText:"知道了" }); + return e }).catch(err=>{ if('nickname' in data){ uni.showModal({ @@ -320,6 +325,7 @@ }); } console.log("错误------",err); + return err /* uni.showModal({ title:"执行更新操作失败!", content: "schema配置了,更新该字段限:\n 1、数据创建者,2、审核员,3、当然还有无任何权限限制的管理员", @@ -330,10 +336,10 @@ uni.hideLoading() }) }, - getFn(field='uid,username,nickname,state'){ + async getFn(field='uid,username,nickname,state'){ // console.time('getFn'); uni.showLoading({mask:true}) - ptDb.field(field).get() + return await ptDb.field(field).get() .then(e=>{ // console.timeEnd('getFn'); console.log(e); @@ -347,6 +353,7 @@ confirmText:"知道了" }); } + return e.result }).catch(err=>{ // console.timeEnd('getFn'); console.log(err,"err---"); @@ -356,6 +363,7 @@ showCancel: false, confirmText:"知道了" }); + return err }).finally(() => { uni.hideLoading() }) diff --git a/pages/clientDB/permission-field-simple/permission-field-simple.test.js b/pages/clientDB/permission-field-simple/permission-field-simple.test.js index 5e44882fcccd79ed64236ddda5981cf0287c6f73..afa4c1ef54203771ae32cc3e8be8c403f2b161fd 100644 --- a/pages/clientDB/permission-field-simple/permission-field-simple.test.js +++ b/pages/clientDB/permission-field-simple/permission-field-simple.test.js @@ -1,16 +1,18 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', () => { - let page + let page,errMsgA,errMsgB; beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch( '/pages/clientDB/permission-field-simple/permission-field-simple') - if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus") { - await page.waitFor(1000) - } - if (process.env.UNI_PLATFORM === "mp-weixin") { - await page.waitFor(1000);//微信等待 - } + await page.waitFor(1000) page = await program.currentPage() + + // 权限校验未通过 + // 未能获取当前用户信息:30205 | 当前用户为匿名身份 + + errMsgA = "权限校验未通过,参与权限校验的集合:[],请参考文档:https://uniapp.dcloud.net.cn/uniCloud/schema.html#handler-permission-error" + + errMsgB = "权限校验未通过,未能获取当前用户信息,当前用户为匿名身份 ,参与权限校验的集合:[],请参考文档:https://uniapp.dcloud.net.cn/uniCloud/schema.html#handler-permission-error" }) // beforeEach(async()=>{ @@ -34,7 +36,7 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', return createUnloginIndex === 0 && createUnloginRole === 0 }) - console.log("createUnlogin: ",createUnlogin); + // console.log("createUnlogin: ",createUnlogin); const createA = await page.callMethod('myFn', { "type": "create", @@ -64,7 +66,7 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', "type": "create", "index": 2, }) - expect(createC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(createC).toBe(errMsgB) await page.callMethod('myFn', { "type": "create", @@ -91,14 +93,14 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', const readUnloginRole = await page.data('currentRole') return readUnloginIndex === 1 && readUnloginRole === 0 }) - console.log("readUnlogin: ",readUnlogin); + // console.log("readUnlogin: ",readUnlogin); const readA = await page.callMethod('myFn', { "type": "read", "index": 0 }) - console.log("readA: ",readA); - // expect(readA).toBe('权限校验未通过') + // console.log("readA: ",readA); + expect(readA).toBe(errMsgB) await page.callMethod('myFn', { "type": "read", @@ -110,7 +112,7 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', "type": "read", "index": 1 }) - expect(readB).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(readB).toBe(errMsgB) await page.callMethod('myFn', { "type": "read", @@ -122,7 +124,7 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', "type": "read", "index": 2 }) - expect(readC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(readC).toBe(errMsgB) await page.callMethod('myFn', { "type": "read", @@ -146,14 +148,14 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', const updateUnloginRole = await page.data('currentRole') return updateUnloginIndex === 2 && updateUnloginRole === 0 }) - console.log("updateUnlogin: ",updateUnlogin); + // console.log("updateUnlogin: ",updateUnlogin); const updateA = await page.callMethod('myFn', { "type": "update", "index": 0 }) - console.log("updateA: ",updateA); - // expect(updateA).toBe('权限校验未通过') + // console.log("updateA: ",updateA); + expect(updateA).toBe(errMsgB) await page.callMethod('myFn', { "type": "update", @@ -165,7 +167,8 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', "type": "update", "index": 1 }) - expect(updateB).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + // expect(updateB).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(updateB).toBe(errMsgB) await page.callMethod('myFn', { "type": "update", @@ -177,7 +180,7 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', "type": "update", "index": 2 }) - expect(updateC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(updateC).toBe(errMsgB) await page.callMethod('myFn', { "type": "update", @@ -211,8 +214,8 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', "type": "create", "index": 0, }) - console.log("createUserA: ",createUserA); - // expect(createUserA).toBe('[permission-test-10.ip.write]权限校验未通过') + // console.log("createUserA: ",createUserA); + expect(createUserA).toBe(errMsgA) await page.callMethod('myFn', { "type": "create", @@ -260,13 +263,13 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', return readUserIndex === 1 && readUserRole == 'user' }) - console.log("readUser: ",readUser); + // console.log("readUser: ",readUser); const readUserA = await page.callMethod('myFn', { "type": "read", "index": 0 }) - expect(readUserA).toBe('权限校验未通过') + expect(readUserA).toBe(errMsgA) await page.callMethod('myFn', { "type": "read", @@ -289,7 +292,7 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', "type": "read", "index": 2 }) - expect(readUserB).toBe('权限校验未通过') + expect(readUserB).toBe(errMsgA) await page.callMethod('myFn', { "type": "read", @@ -320,7 +323,7 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', "type": "update", "index": 0 }) - expect(updateUserA).toBe('权限校验未通过') + expect(updateUserA).toBe(errMsgA) await page.callMethod('myFn', { "type": "update", @@ -343,7 +346,7 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', "type": "update", "index": 2 }) - expect(updateUserB).toBe('权限校验未通过') + expect(updateUserB).toBe(errMsgA) await page.callMethod('myFn', { "type": "update", @@ -375,8 +378,9 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', "type": "create", "index": 0, }) - console.log("createAuditorA: ",createAuditorA); + // console.log("createAuditorA: ",createAuditorA); // expect(createAuditorA).toBe('[permission-test-10.ip.write]权限校验未通过') + expect(createAuditorA).toBe(errMsgA) await page.callMethod('myFn', { "type": "create", @@ -428,7 +432,7 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', "type": "read", "index": 0 }) - expect(readAuditorA).toBe('权限校验未通过') + expect(readAuditorA).toBe(errMsgA) await page.callMethod('myFn', { "type": "read", @@ -479,7 +483,7 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', "type": "update", "index": 0 }) - expect(updateAuditorA).toBe('权限校验未通过') + expect(updateAuditorA).toBe(errMsgA) await page.callMethod('myFn', { "type": "update", diff --git a/pages/clientDB/permission-field-simple/permission-field-simple.vue b/pages/clientDB/permission-field-simple/permission-field-simple.vue index c0130fd91655cd017a3fdb01a544fde39ea27575..7eee9e3e16cdd5f6c64dacf5c9f6b3a76e269762 100644 --- a/pages/clientDB/permission-field-simple/permission-field-simple.vue +++ b/pages/clientDB/permission-field-simple/permission-field-simple.vue @@ -184,6 +184,7 @@ } console.log("res: ",res); this.$refs.alertCode.open(res.result) + return res } catch (err) { console.log('TODO handle the exception', err); uni.showModal({ @@ -191,6 +192,7 @@ content: item.explain +'【'+ this.typeText+'字段'+item.field+'】' + (item.explain_end?item.explain_end:''), showCancel: false }); + return err.message } finally{ uni.hideLoading() } diff --git a/pages/clientDB/permission-table-compound/permission-table-compound.test.js b/pages/clientDB/permission-table-compound/permission-table-compound.test.js index b1a01e9ea17deaa0e87e8b1a2b3d59e7d24ceceb..322c4c666658a6fa9d9617393111b66e94992944 100644 --- a/pages/clientDB/permission-table-compound/permission-table-compound.test.js +++ b/pages/clientDB/permission-table-compound/permission-table-compound.test.js @@ -1,25 +1,22 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue', () => { - let page + let page,errMsgA,errMsgB; beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch( '/pages/clientDB/permission-table-compound/permission-table-compound') if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus") { - await page.waitFor(1000) + await page.waitFor(500) } if (process.env.UNI_PLATFORM === "mp-weixin") { await page.waitFor(1000);//微信等待 } - // page = await program.currentPage() - // console.log("page------------------: ",page); + errMsgA = "权限校验未通过,参与权限校验的集合:[],请参考文档:https://uniapp.dcloud.net.cn/uniCloud/schema.html#handler-permission-error" + + errMsgB = "权限校验未通过,未能获取当前用户信息,当前用户为匿名身份 ,参与权限校验的集合:[],请参考文档:https://uniapp.dcloud.net.cn/uniCloud/schema.html#handler-permission-error" + // page = await program.currentPage() }) - // beforeEach(async()=>{ - // jest.setTimeout(30000) - // return false - // }) - it('创建--未登陆', async () => { const perPage = await page.$('.page') @@ -44,7 +41,7 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue "type": "create", "index": 1 }) - // expect(createA).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(createA).toBe(errMsgB) await page.callMethod('myFn', { "type": "create", @@ -91,13 +88,13 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue "type": "read", "index": 0 }) - expect(readB).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(readB).toBe(errMsgB) const readC = await page.callMethod('myFn', { "type": "read", "index": 1 }) - expect(readC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(readC).toBe(errMsgB) await page.callMethod('myFn', { "type": "read", @@ -105,8 +102,6 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue "action": "add_view_count" }) - - }) it('更新--未登陆', async () => { @@ -137,20 +132,20 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue "index": 0, "where": "create_time > 1613534788761" }) - expect(updateA).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(updateA).toBe(errMsgB) const updateB = await page.callMethod('myFn', { "type": "update", "index": 0 }) - console.log("updateB: ",updateB); + // console.log("updateB: ",updateB); // expect(updateB).toBe('权限校验未通过') const updateC = await page.callMethod('myFn', { "type": "update", "index": 1 }) - expect(updateC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(updateC).toBe(errMsgB) await page.callMethod('myFn', { "type": "update", @@ -159,7 +154,6 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue }) - }) it('删除--未登陆', async () => { @@ -191,7 +185,7 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue "index": 0, "where": "create_time > 1613534788761" }) - expect(deleteA).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(deleteA).toBe(errMsgB) const deleteB = await page.callMethod('myFn', { "type": "delete", @@ -204,7 +198,7 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue "type": "delete", "index": 1 }) - expect(deleteC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(deleteC).toBe(errMsgB) await page.callMethod('myFn', { "type": "delete", @@ -212,13 +206,10 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue "action": "add_view_count" }) - - }) - it('创建--用户', async () => { const perPage = await page.$('.page') //头部操作控制条 @@ -344,7 +335,7 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue "type": "update", "index": 0 }) - expect(updateUserB).toBe('权限校验未通过') + expect(updateUserB).toBe(errMsgA) await page.callMethod('myFn', { "type": "update", @@ -389,13 +380,13 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue "index": 0, "where": "create_time > 1613534788761" }) - expect(deleteUserA).toBe('权限校验未通过') + expect(deleteUserA).toBe(errMsgA) const deleteUserB = await page.callMethod('myFn', { "type": "delete", "index": 0 }) - expect(deleteUserB).toBe('权限校验未通过') + expect(deleteUserB).toBe(errMsgA) await page.callMethod('myFn', { "type": "delete", @@ -532,7 +523,7 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue "type": "update", "index": 0 }) - expect(updateAuditorA).toBe('权限校验未通过') + expect(updateAuditorA).toBe(errMsgA) await page.callMethod('myFn', { "type": "update", @@ -582,7 +573,7 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue "type": "delete", "index": 0 }) - expect(deleteAuditorB).toBe('权限校验未通过') + expect(deleteAuditorB).toBe(errMsgA) await page.callMethod('myFn', { "type": "delete", diff --git a/pages/clientDB/permission-table-compound/permission-table-compound.vue b/pages/clientDB/permission-table-compound/permission-table-compound.vue index 63dfe067b7e5c130cafec73b7ea8b06f12106adb..e569a8d5280940adada46dcb60dfa600ebde64a7 100644 --- a/pages/clientDB/permission-table-compound/permission-table-compound.vue +++ b/pages/clientDB/permission-table-compound/permission-table-compound.vue @@ -158,6 +158,7 @@ } console.log("res: ",res); this.$refs.alertCode.open(res.result) + return res } catch (err) { console.log('TODO handle the exception', err); uni.showModal({ @@ -165,6 +166,7 @@ content: item.explain +'【'+ this.typeText+'数据】' + (item.explain_end?item.explain_end:''), showCancel: false }); + return err.message } finally{ uni.hideLoading() } diff --git a/pages/clientDB/permission-table-simple/permission-table-simple.test.js b/pages/clientDB/permission-table-simple/permission-table-simple.test.js index a1dbd0e9b44381d68a1539f9f79ae8c95429364e..d7d1a759ab2f018b18847f238a7ea3dc29b4cb22 100644 --- a/pages/clientDB/permission-table-simple/permission-table-simple.test.js +++ b/pages/clientDB/permission-table-simple/permission-table-simple.test.js @@ -1,22 +1,25 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', () => { - let page + let page,errMsgA,errMsgB,errMsgC; beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch( '/pages/clientDB/permission-table-simple/permission-table-simple') - if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus") { - await page.waitFor(1000) - } - if (process.env.UNI_PLATFORM === "mp-weixin") { - await page.waitFor(1000);//微信等待 - } + + await page.waitFor(1000) + + errMsgA = "权限校验未通过,参与权限校验的集合:[],请参考文档:https://uniapp.dcloud.net.cn/uniCloud/schema.html#handler-permission-error" + + errMsgB = "权限校验未通过,未能获取当前用户信息,当前用户为匿名身份 ,参与权限校验的集合:[],请参考文档:https://uniapp.dcloud.net.cn/uniCloud/schema.html#handler-permission-error" + + errMsgC = "未能获取当前用户信息:当前用户为匿名身份" + page = await program.currentPage() }) - // beforeEach(async()=>{ - // jest.setTimeout(30000) - // return false - // }) + beforeEach(async()=>{ + jest.setTimeout(20000) + return false + }) it('创建--未登陆', async () => { @@ -43,12 +46,13 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( console.log(createUnlogin, "创建--未登陆"); if (createUnlogin) { - - await page.callMethod('myFn', { + // 允许任何角色创建本表 + const createData = await page.callMethod('myFn', { "type": "create", "index": 0 }) - + expect(createData.success).toBeTruthy() + const createA = await page.callMethod('myFn', { "type": "create", "index": 1 @@ -65,7 +69,6 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "create", "index": 5 }) - // console.log("createC: ", createC); // expect(createC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') @@ -73,10 +76,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "create", "index": 6 }) - - console.log("createD: =================",createD); - // expect(createD.id).toBeTruthy() - // expect(createD).toBe('[permission-test-7.create]权限校验未通过') + // expect(createD.errMsg).toBe(errMsgB) await page.callMethod('myFn', { "type": "create", @@ -107,52 +107,53 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( //console.log(readUnlogin, '读取--未登陆'); - if (readUnlogin) { - - await page.callMethod('myFn', { + // 含义解释:允许任何角色【读取】 + const readAll = await page.callMethod('myFn', { "type": "read", "index": 0 }) - + expect(readAll.errCode).toBe(0) + + // 禁止任何角色读取 const readA = await page.callMethod('myFn', { "type": "read", "index": 1 }) - //console.log(readA,"readA---------"); //expect(readA).toBe('权限校验未通过') const readB = await page.callMethod('myFn', { "type": "read", "index": 2 }) - expect(readB).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') - + expect(readB.errMsg).toBe(errMsgB) + + // 只能读取自己创建的数据 const readC = await page.callMethod('myFn', { "type": "create", "index": 3 }) - expect(readC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + // expect(readC.errMsg).toBe(errMsgB) const readD = await page.callMethod('myFn', { "type": "read", "index": 3, "where": "uid == $env.uid" }) - expect(readD).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') - + expect(readD.errMsg).toBe(errMsgC) + const readE = await page.callMethod('myFn', { "type": "read", "index": 3 }) - expect(readE).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + // expect(readE.errCode).toBe(0) const readF = await page.callMethod('myFn', { "type": "create", "index": 4 }) - expect(readF).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + // expect(readF.errCode).toBe(0) await page.callMethod('myFn', { @@ -165,29 +166,27 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "read", "index": 4 }) - + // 限审核员读取 const readG = await page.callMethod('myFn', { "type": "create", "index": 5 }) - expect(readG).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(readG.errMsg).toBe(errMsgC) const readH = await page.callMethod('myFn', { "type": "create", "index": 6 }) - console.log("readH: =================",readH); - expect(readH).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') - - + expect(readH.errMsg).toBe(errMsgB) // expect(readH).toBe('[permission-test-7.create]权限校验未通过') - await page.callMethod('myFn', { + const actionRead = await page.callMethod('myFn', { "type": "read", "index": 6, "action": "add_view_count" }) + expect(actionRead.errCode).toBe(0) } }) @@ -222,42 +221,40 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "update", "index": 1 }) - console.log("updateA:----------------- ",updateA); - expect(updateA).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') - // expect(updateA).toBe('权限校验未通过') + expect(updateA.errMsg).toBe(errMsgB) const updateB = await page.callMethod('myFn', { "type": "update", "index": 2 }) - expect(updateB).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(updateB.errMsg).toBe(errMsgB) const updateC = await page.callMethod('myFn', { "type": "create", "index": 3 }) - expect(updateC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(updateC.errMsg).toBe(errMsgC) const updateD = await page.callMethod('myFn', { "type": "update", "index": 3, "where": "uid == $env.uid" }) - expect(updateD).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(updateD.errMsg).toBe(errMsgC) const updateE = await page.callMethod('myFn', { "type": "update", "index": 3 }) - expect(updateE).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(updateE.success).toBeTruthy() const updateF = await page.callMethod('myFn', { "type": "create", "index": 4 }) - expect(updateF).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + // expect(updateF.errCode).toBe(0) await page.callMethod('myFn', { @@ -276,14 +273,13 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "update", "index": 5 }) - expect(updateG).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(updateG.errMsg).toBe(errMsgB) const updateH = await page.callMethod('myFn', { "type": "update", "index": 6 }) - // expect(updateH).toBe('权限校验未通过') - expect(updateH).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + // expect(updateH.errMsg).toBe(errMsgB) await page.callMethod('myFn', { @@ -326,42 +322,42 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "delete", "index": 1 }) - console.log("deleteA: -------------------",deleteA); - expect(deleteA).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(deleteA.errMsg).toBe(errMsgB) // expect(deleteA).toBe('权限校验未通过') const deleteB = await page.callMethod('myFn', { "type": "delete", "index": 2 }) - expect(deleteB).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(deleteB.errMsg).toBe(errMsgB) const deleteC = await page.callMethod('myFn', { "type": "create", "index": 3 }) - expect(deleteC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(deleteC.errMsg).toBe(errMsgC) const deleteD = await page.callMethod('myFn', { "type": "delete", "index": 3, "where": "uid == $env.uid" }) - expect(deleteD).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(deleteD.errMsg).toBe(errMsgC) const deleteE = await page.callMethod('myFn', { "type": "delete", "index": 3 }) - expect(deleteE).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + expect(deleteE.success).toBeTruthy() const deleteF = await page.callMethod('myFn', { "type": "create", "index": 4 }) - expect(deleteF).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + console.log('deleteF: ',deleteF); + expect(deleteF.errMsg).toBe(errMsgC) await page.callMethod('myFn', { @@ -380,14 +376,14 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "delete", "index": 5 }) - expect(deleteG).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + // expect(deleteG).toBe(errMsgB) const deleteH = await page.callMethod('myFn', { "type": "delete", "index": 6 }) - // expect(deleteH).toBe('权限校验未通过') - expect(deleteH).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份') + console.log('deleteH: ',deleteH); + expect(deleteH.errMsg).toBe(errMsgB) await page.callMethod('myFn', { @@ -432,9 +428,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "create", "index": 1 }) - console.log("createUserA:---------------- ",createUserA); - expect(createUserA).toBe('权限校验未通过') - // expect(createUserA).toBe('[permission-test-2.create]权限校验未通过') + console.log('createUserA: ',createUserA); await page.callMethod('myFn', { "type": "create", @@ -446,13 +440,11 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "index": 5 }) // expect(createUserB).toBe('[permission-test-6.create]权限校验未通过') - //未能获取当前用户信息:30205 | 当前用户为匿名身份 const createUserC = await page.callMethod('myFn', { "type": "create", "index": 6 }) - console.log("createUserC: ",createUserC); // expect(createUserC.id).toBeTruthy() // expect(createUserC).toBe('[permission-test-7.create]权限校验未通过') @@ -492,7 +484,8 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "read", "index": 1 }) - expect(readUserA).toBe('权限校验未通过') + // console.log('readUserA: ',readUserA); + // expect(readUserA.errMsg).toBe(errMsgA) await page.callMethod('myFn', { "type": "read", @@ -535,14 +528,14 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "read", "index": 5 }) - expect(readUserB).toBe('权限校验未通过') + expect(readUserB.errMsg).toBe(errMsgA) const readUserC = await page.callMethod('myFn', { "type": "read", "index": 6 }) - expect(readUserC).toBe('权限校验未通过') + expect(readUserC.errMsg).toBe(errMsgA) await page.callMethod('myFn', { "type": "read", @@ -583,7 +576,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "update", "index": 1 }) - expect(updateUserA).toBe('权限校验未通过') + expect(updateUserA.errMsg).toBe(errMsgA) const updateUserB = await page.callMethod('myFn', { "type": "update", @@ -631,13 +624,13 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "update", "index": 5 }) - expect(updateUserC).toBe('权限校验未通过') + expect(updateUserC.errMsg).toBe(errMsgA) const updateUserD = await page.callMethod('myFn', { "type": "update", "index": 6 }) - expect(updateUserD).toBe('权限校验未通过') + expect(updateUserD.errMsg).toBe(errMsgA) await page.callMethod('myFn', { @@ -678,7 +671,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "delete", "index": 1 }) - expect(deleteUserA).toBe('权限校验未通过') + expect(deleteUserA.errMsg).toBe(errMsgA) await page.callMethod('myFn', { "type": "delete", @@ -721,13 +714,13 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "delete", "index": 5 }) - expect(deleteUserB).toBe('权限校验未通过') + expect(deleteUserB.errMsg).toBe(errMsgA) const deleteUserC = await page.callMethod('myFn', { "type": "delete", "index": 6 }) - expect(deleteUserC).toBe('权限校验未通过') + expect(deleteUserC.errMsg).toBe(errMsgA) await page.callMethod('myFn', { "type": "delete", @@ -735,11 +728,6 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "action": "add_view_count" }) - - - - - }) @@ -772,9 +760,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "create", "index": 1 }) - console.log("createAuditorA:------------",createAuditorA); - expect(createAuditorA).toBe('权限校验未通过') - // expect(createAuditorA).toBe('[permission-test-2.create]权限校验未通过') + expect(createAuditorA.errMsg).toBe(errMsgA) await page.callMethod('myFn', { "type": "create", @@ -791,7 +777,6 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "create", "index": 6 }) - console.log("createAuditorB: ",createAuditorB); // expect(createAuditorB.id).toBeTruthy() // expect(createAuditorB).toBe('[permission-test-7.create]权限校验未通过') @@ -831,7 +816,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "read", "index": 1 }) - expect(readAuditorA).toBe('权限校验未通过') + expect(readAuditorA.errMsg).toBe(errMsgA) await page.callMethod('myFn', { "type": "read", @@ -882,7 +867,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "read", "index": 6 }) - expect(readAuditorB).toBe('权限校验未通过') + expect(readAuditorB.errMsg).toBe(errMsgA) await page.callMethod('myFn', { "type": "read", @@ -924,7 +909,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "update", "index": 1 }) - expect(updateAuditorA).toBe('权限校验未通过') + expect(updateAuditorA.errMsg).toBe(errMsgA) await page.callMethod('myFn', { "type": "update", @@ -973,7 +958,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "update", "index": 6 }) - expect(updateAuditorB).toBe('权限校验未通过') + expect(updateAuditorB.errMsg).toBe(errMsgA) await page.callMethod('myFn', { "type": "update", @@ -1014,7 +999,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "delete", "index": 1 }) - expect(deleteAuditorA).toBe('权限校验未通过') + expect(deleteAuditorA.errMsg).toBe(errMsgA) await page.callMethod('myFn', { "type": "delete", @@ -1066,7 +1051,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "delete", "index": 6 }) - expect(deleteAuditorB).toBe('权限校验未通过') + expect(deleteAuditorB.errMsg).toBe(errMsgA) await page.callMethod('myFn', { "type": "delete", @@ -1398,12 +1383,6 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "action": "add_view_count" }) - - - }) - - - }) diff --git a/pages/clientDB/permission-table-simple/permission-table-simple.vue b/pages/clientDB/permission-table-simple/permission-table-simple.vue index 4f95c44976bc09f99f83f6994973ba1cab5591e1..827529d69dde06fab324bc743dd43761c70a7875 100644 --- a/pages/clientDB/permission-table-simple/permission-table-simple.vue +++ b/pages/clientDB/permission-table-simple/permission-table-simple.vue @@ -203,6 +203,7 @@ } console.log("res: ",res); this.$refs.alertCode.open(res.result) + return res } catch (err) { console.log('TODO handle the exception', err); uni.showModal({ @@ -210,6 +211,7 @@ content: item.explain + '【' + this.typeText + '数据】' + (item.explain_end ? item.explain_end : ''), showCancel: false }); + return err } finally { uni.hideLoading() } diff --git a/pages/clientDB/permission/permission.test.js b/pages/clientDB/permission/permission.test.js index 16dc558ffc338fd9a609045a81b92cf67945f5fa..eb7b1cbe81063ae397fa090d756a9b89a874a084 100644 --- a/pages/clientDB/permission/permission.test.js +++ b/pages/clientDB/permission/permission.test.js @@ -3,12 +3,7 @@ describe('pages/clientDB/permission/permission.vue', () => { beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch('/pages/clientDB/permission/permission') - if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") { - await page.waitFor(1000) - } - if (process.env.UNI_PLATFORM === "mp-weixin") { - await page.waitFor(1000);//微信等待 - } + await page.waitFor(1000) page = await program.currentPage() }) diff --git a/pages/clientDB/unicloud-db-demo/unicloud-db-demo.vue b/pages/clientDB/unicloud-db-demo/unicloud-db-demo.vue index e75a2fdf509adcf5d2c16477596387aa399e1904..fd8d1f8c7e635c05755d907dfbe6d53a7559d474 100644 --- a/pages/clientDB/unicloud-db-demo/unicloud-db-demo.vue +++ b/pages/clientDB/unicloud-db-demo/unicloud-db-demo.vue @@ -201,7 +201,7 @@ return arrJson }, async add(){ - await udb.add({ + return await udb.add({ book_id:"add-test", quantity:Date.now() },{ @@ -212,13 +212,13 @@ } }) }, - remove(){ + async remove(){ const _id = udb.dataList[0]._id - udb.remove(_id) + return await udb.remove(_id) }, - update(){ + async update(){ const _id = udb.dataList[0]._id - udb.update(_id,{book_id:"这条数据被改"}, + return await udb.update(_id,{book_id:"这条数据被改"}, { success: (res) => { // 新增成功后的回调 this.getFn() diff --git a/pages/clientDB/validate/validate.test.js b/pages/clientDB/validate/validate.test.js new file mode 100644 index 0000000000000000000000000000000000000000..ef92c8c40cf923977a906b8ad388e6948a6ffeff --- /dev/null +++ b/pages/clientDB/validate/validate.test.js @@ -0,0 +1,32 @@ +describe('pages/clientDB/validate/validate.vue', () => { + + let page + beforeAll(async () => { + // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) + page = await program.reLaunch('/pages/clientDB/validate/validate') + await page.waitFor(1000) + page = await program.currentPage() + }) + + beforeEach(async()=>{ + jest.setTimeout(5000) + return false + }) + + it('点击切换navBar', async () => { + //expect.assertions(1); + const segmentedControl = await page.$('.segmented-control') + + const seControl = await segmentedControl.$$('.segmented-control__item') + // console.log(await seControl[0].text()); + expect(await seControl[0].text()).toBe('实例demo') + + await seControl[1].tap() + await page.waitFor(300) + + await seControl[2].tap() + await page.waitFor(300) + + }) + +}) diff --git a/pages/cloudFunction/cloudFunction.test.js b/pages/cloudFunction/cloudFunction.test.js index e379626fa01fd92a26145b4298e4c48279b2bdd8..3f3d8c7aa627269d28f970795aec27f0a0f56d31 100644 --- a/pages/cloudFunction/cloudFunction.test.js +++ b/pages/cloudFunction/cloudFunction.test.js @@ -4,12 +4,7 @@ describe('pages/cloudFunction/cloudFunction.vue', () => { beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch('/pages/cloudFunction/cloudFunction') - if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") { - await page.waitFor(1000) - } - if (process.env.UNI_PLATFORM === "mp-weixin") { - await page.waitFor(1000);//微信等待 - } + await page.waitFor(1000) page = await program.currentPage() }) diff --git a/pages/cloudFunction/cloudFunction.vue b/pages/cloudFunction/cloudFunction.vue index 4f1b078e2481eccd3a2c4d28581ca2f1b645949a..1b8b9aff4234333da29055a69702e6b414294afe 100644 --- a/pages/cloudFunction/cloudFunction.vue +++ b/pages/cloudFunction/cloudFunction.vue @@ -24,11 +24,11 @@ return {} }, methods: { - add() { + async add() { uni.showLoading({ title: '处理中...' }) - uniCloud.callFunction({ + return await uniCloud.callFunction({ name: 'add', data: { name: 'DCloud', @@ -42,6 +42,7 @@ showCancel: false }) console.log(res) + return res.result.id }).catch((err) => { uni.hideLoading() uni.showModal({ @@ -52,7 +53,7 @@ return err }) }, - remove() { + async remove() { uni.showLoading({ title: '处理中...' }) @@ -65,6 +66,7 @@ showCancel: false }) console.log(res) + return res.result.msg }).catch((err) => { uni.hideLoading() uni.showModal({ @@ -72,13 +74,14 @@ showCancel: false }) console.error(err) + return err }) }, - update() { + async update() { uni.showLoading({ title: '处理中...' }) - uniCloud.callFunction({ + return await uniCloud.callFunction({ name: 'update', data: { name: 'DCloud', @@ -92,6 +95,7 @@ showCancel: false }) console.log(res) + return res.result.msg }).catch((err) => { uni.hideLoading() uni.showModal({ @@ -102,11 +106,11 @@ return err }) }, - get() { + async get() { uni.showLoading({ title: '处理中...' }) - uniCloud.callFunction({ + return await uniCloud.callFunction({ name: 'get' }).then((res) => { uni.hideLoading() @@ -115,6 +119,7 @@ showCancel: false }) console.log(res) + return res.result.data }).catch((err) => { uni.hideLoading() uni.showModal({ @@ -122,11 +127,12 @@ showCancel: false }) console.error(err) + return err }) }, - useCommon() { + async useCommon() { console.log('请确保自己已经阅读并按照公用模块文档操作 https://uniapp.dcloud.io/uniCloud/cf-common') - uniCloud.callFunction({ + return await uniCloud.callFunction({ name: 'use-common' }).then((res) => { uni.hideLoading() @@ -135,6 +141,7 @@ showCancel: false }) console.log(res) + return res.result }).catch((err) => { uni.hideLoading() uni.showModal({ @@ -142,6 +149,7 @@ showCancel: false }) console.error(err) + return err }) }, toRedisPage(){ diff --git a/pages/cloudObject/cloudObject.test.js b/pages/cloudObject/cloudObject.test.js index 5c66881bf38f6cf980d3f10a67d71c83a5f016de..69a1a37b2e07bd2e338b2855ff54510ce6acdbee 100644 --- a/pages/cloudObject/cloudObject.test.js +++ b/pages/cloudObject/cloudObject.test.js @@ -5,42 +5,36 @@ describe('pages/cloudObject/cloudObject.vue', () => { let page; beforeAll(async () => { page = await program.reLaunch('/pages/cloudObject/cloudObject') - console.log("page: ",page); await page.waitFor(500); }); it('云对象-检查标题',async()=>{ expect.assertions(1); const title = await page.$('.title') - console.log("title: ",await title.text()); expect(await title.text()).toBe('基础示例-云对象'); }) it('新增一条数据',async()=>{ expect.assertions(1); const addData = await page.callMethod('add') - console.log("addData: ",addData); expect(addData).toBeDefined(); }) it('删除一条数据',async()=>{ expect.assertions(1); const removeData = await page.callMethod('remove') - console.log("removeData: ",removeData); expect(removeData).toBe('成功删除unicloud-test内第一条数据'); }) it('修改数据',async()=>{ expect.assertions(1); const updateData = await page.callMethod('update') - console.log("updateData: ",updateData); expect(updateData).toBeDefined(); }) it('查询前10条数据',async()=>{ // expect.assertions(1); const getTenData = await page.callMethod('get') - console.log("getTenData: ",getTenData); console.log("getTenData.data.length: ",getTenData.data.length); // expect(getTenData.length).not.toBeUndefined(); expect(getTenData.data.length).toBeGreaterThanOrEqual(1); @@ -51,11 +45,8 @@ describe('pages/cloudObject/cloudObject.vue', () => { it('使用公用模块',async()=>{ expect.assertions(1); const useCommon = await page.callMethod('useCommon') - console.log("useCommon: ",useCommon); const record = {"secret":"abcdefg","version":"1.0.0"} expect(useCommon).toEqual(record); }) - - }); diff --git a/pages/cloudObject/cloudObject.vue b/pages/cloudObject/cloudObject.vue index cf2f87e08e587d46bc808075c9734c1bede5ada0..a9a755499a13873b925cc2b29f7c2a6cd862792a 100644 --- a/pages/cloudObject/cloudObject.vue +++ b/pages/cloudObject/cloudObject.vue @@ -102,6 +102,7 @@ showCancel: false }) console.log(res) + return res }).catch((err) => { uni.hideLoading() uni.showModal({ diff --git a/pages/storage/storage.test.js b/pages/storage/storage.test.js index 076078db5e30a53f7a4e71d8a9a1f695273fc00a..8add142ba57304298efbe7270e5a5181d74e6307 100644 --- a/pages/storage/storage.test.js +++ b/pages/storage/storage.test.js @@ -4,24 +4,21 @@ describe('pages/storage/storage.nvue', () => { beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch('/pages/storage/storage') - if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") { - await page.waitFor(1000) - } - if (process.env.UNI_PLATFORM === "mp-weixin") { - await page.waitFor(1000);//微信等待 - } + await page.waitFor(300) page = await program.currentPage() }) - beforeEach(async()=>{ - jest.setTimeout(5000) - return false - }) + // beforeEach(async()=>{ + // console.log('beforeEach---') + // jest.setTimeout(300) + // return; + // }) it('云存储页-检查标题',async()=>{ //expect.assertions(1); - await page.waitFor(300) + // await page.waitFor(300) const content = await page.$('.content') + console.log('content: ',content); await page.waitFor(300) const title = await content.$('.title') diff --git a/pages/storage/storage.vue b/pages/storage/storage.vue index 1aa986dbb83b5502090cd016091643ba0d7043a4..40416f0ac247548ff22d683b4da31d2b1c754f17 100644 --- a/pages/storage/storage.vue +++ b/pages/storage/storage.vue @@ -56,12 +56,14 @@ content: JSON.stringify(res), showCancel: false }); + return res }).catch((err) => { console.log(err); uni.showModal({ content: JSON.stringify(err), showCancel: false }); + return err }).finally(() => { uni.hideLoading() }) diff --git a/pages/user-info/add.test.js b/pages/user-info/add.test.js index 144dce16ad4b49a744629f354cb99cd42f94a14e..3d65cca43d4af1cf802f65152acd15e0685b857d 100644 --- a/pages/user-info/add.test.js +++ b/pages/user-info/add.test.js @@ -24,7 +24,7 @@ describe('pages/user-info/add.vue', () => { const getForm = await page.data('formData') - console.log("getForm: ",getForm); + // console.log("getForm: ",getForm); let username = "林小明" let weight = 51 diff --git a/pages/user-info/add.vue b/pages/user-info/add.vue index d71f50b7fa08dbd5b675713fa6d6014f6c03c21f..494466045c228e5338883aaff1a662f75d022c2a 100644 --- a/pages/user-info/add.vue +++ b/pages/user-info/add.vue @@ -120,31 +120,35 @@ /** * 触发表单提交 */ - submit() { + async submit() { uni.showLoading({ mask: true }) - this.$refs.form.validate().then((res) => { - this.submitForm(res) + return this.$refs.form.validate().then(async(res) => { + console.log('res: ',res); + await this.submitForm(res) + return res }).catch(() => { uni.hideLoading() }) }, - submitForm(value) { + async submitForm(value) { // 使用 clientDB 提交数据 - db.collection(dbCollectionName).add(value).then((res) => { + return await db.collection(dbCollectionName).add(value).then((res) => { uni.showToast({ icon: 'none', title: '新增成功' }) this.getOpenerEventChannel().emit('refreshData') setTimeout(() => uni.navigateBack(), 500) + return res }).catch((err) => { uni.showModal({ content: err.message || '请求服务失败', showCancel: false }) + return err }).finally(() => { uni.hideLoading() }) diff --git a/pages/user-info/detail.test.js b/pages/user-info/detail.test.js index 0c0b9edc89c94ce8e69153258385be96ea330255..615400d7f9dbdaba24e85df756e54008648cda9b 100644 --- a/pages/user-info/detail.test.js +++ b/pages/user-info/detail.test.js @@ -3,26 +3,12 @@ describe('pages/user-info/detail.vue', () => { let page beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) - ///pages/user-info/detail?id=601d044ac9e7be0001cc00b8 - page = await program.reLaunch('/pages/user-info/detail') - if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") { - await page.waitFor(1000) - } - if (process.env.UNI_PLATFORM === "mp-weixin") { - await page.waitFor(1000);//微信等待 - } + await page.waitFor(1000) page = await program.currentPage() - }) - // beforeEach(async()=>{ - // jest.setTimeout(10000) - // return false - // }) - - it('点击修改',async()=>{ const getId = await page.data('_id') diff --git a/pages/user-info/detail.vue b/pages/user-info/detail.vue index 9bcbb7b3f6d67cc2c45093d9632ad9c9fcdae096..46d52561c6857a451366309ac26612853ef84812 100644 --- a/pages/user-info/detail.vue +++ b/pages/user-info/detail.vue @@ -79,10 +79,12 @@ options: { // 将scheme enum 属性静态数据中的value转成text ...enumConverter - } + }, + _id:'' } }, onLoad(e) { + console.log('e:-----id ',e); this._id = e.id }, onReady() { diff --git a/pages/user-info/edit.vue b/pages/user-info/edit.vue index d0b87a49d05f430c4825238ac14f242407852586..07103a8f3c252b562609f7e68e0501dc91e70b15 100644 --- a/pages/user-info/edit.vue +++ b/pages/user-info/edit.vue @@ -131,27 +131,29 @@ uni.showLoading({ mask: true }) - this.$refs.form.validate().then((res) => { - this.submitForm(res) + return this.$refs.form.validate().then(async(res) => { + return await this.submitForm(res) }).catch(() => { uni.hideLoading() }) }, - submitForm(value) { + async submitForm(value) { // 使用 clientDB 提交数据 - db.collection(dbCollectionName).doc(this.formDataId).update(value).then((res) => { + return await db.collection(dbCollectionName).doc(this.formDataId).update(value).then((res) => { uni.showToast({ icon: 'none', title: '修改成功' }) this.getOpenerEventChannel().emit('refreshData') setTimeout(() => uni.navigateBack(), 500) + return res }).catch((err) => { uni.showModal({ content: err.message || '请求服务失败', showCancel: false }) + return err }).finally(() => { uni.hideLoading() }) diff --git a/pages/validate-demo/add.vue b/pages/validate-demo/add.vue index ea15a7fa2d622cd2a7ea827b5b8fd87741762a10..e16173b5a934bbec30479ef0cb706360f9d5c3c9 100644 --- a/pages/validate-demo/add.vue +++ b/pages/validate-demo/add.vue @@ -119,21 +119,24 @@ /** * 触发表单提交 */ - submit() { + async submit() { uni.showLoading({ mask: true }) - this.$refs.form.submit().then((res) => { + return this.$refs.form.submit().then(async(res) => { console.log(res,"000"); - this.submitForm(res) + let msg = await this.submitForm(res) + console.log(msg,121399999); + return res + // this.submitForm(res) }).catch((errors) => { uni.hideLoading() }) }, - submitForm(value) { + async submitForm(value) { // 使用 clientDB 提交数据 - db.collection(dbCollectionName).add(value).then((res) => { + return await db.collection(dbCollectionName).add(value).then((res) => { console.log("res:---- ",res); uni.showToast({ icon: 'none', @@ -141,11 +144,13 @@ }) // this.getOpenerEventChannel().emit('refreshData') // setTimeout(() => uni.navigateBack(), 500) + return res }).catch((err) => { uni.showModal({ content: err.message || '请求服务失败', showCancel: false }) + return err }).finally(() => { uni.hideLoading() }) diff --git a/uniCloud-aliyun/database/opendb-verify-codes.schema.json b/uniCloud-aliyun/database/opendb-verify-codes.schema.json deleted file mode 100644 index 0c39c7773145f8210b0d555dc04ece68cd866693..0000000000000000000000000000000000000000 --- a/uniCloud-aliyun/database/opendb-verify-codes.schema.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "bsonType": "object", - "required": [], - "properties": { - "_id": { - "description": "ID,系统自动生成" - }, - "mobile": { - "bsonType": "string", - "description": "手机号码" - }, - "email": { - "bsonType": "string", - "description": "邮箱" - }, - "code": { - "bsonType": "string", - "description": "验证码" - }, - "type": { - "bsonType": "string", - "description": "验证类型:login, bind, unbind, pay" - }, - "state": { - "bsonType": "int", - "description": "验证状态:0 未验证、1 已验证、2 已作废" - }, - "ip": { - "bsonType": "string", - "description": "请求时客户端IP地址" - }, - "created_at": { - "bsonType": "timestamp", - "description": "创建时间" - }, - "expired_at": { - "bsonType": "timestamp", - "description": "过期时间" - } - } -} diff --git a/uni_modules/uni-upgrade-center/uniCloud/database/db_init.json b/uni_modules/uni-upgrade-center/uniCloud/database/db_init.json deleted file mode 100644 index c7eb5f49d7b12e97f34b4640353898ab7ef818e9..0000000000000000000000000000000000000000 --- a/uni_modules/uni-upgrade-center/uniCloud/database/db_init.json +++ /dev/null @@ -1,56 +0,0 @@ -// 在本文件中可配置云数据库初始化,数据格式见:https://uniapp.dcloud.io/uniCloud/hellodb?id=db-init - -// 编写完毕后对本文件点右键,可按配置规则创建表和添加数据 - -{ - "opendb-app-list": { - "data": [], - "index": [{ - "IndexName": "appid", - "MgoKeySchema": { - "MgoIndexKeys": [{ - "Name": "appid", - "Direction": "1" - }], - "MgoIsUnique": true - } - }, { - "IndexName": "name", - "MgoKeySchema": { - "MgoIndexKeys": [{ - "Name": "name", - "Direction": "1" - }], - "MgoIsUnique": false - } - }] - }, - "opendb-app-versions": { - "data": [], - "index": [{ - "IndexName": "appid", - "MgoKeySchema": { - "MgoIndexKeys": [{ - "Name": "appid", - "Direction": "1" - }], - "MgoIsUnique": false - } - }, { - "IndexName": "查找上线发行应用", - "MgoKeySchema": { - "MgoIndexKeys": [{ - "Name": "appid", - "Direction": "1" - }, { - "Name": "platform", - "Direction": "1" - }, { - "Name": "stable_publish", - "Direction": "1" - }], - "MgoIsUnique": false - } - }] - } -}