permission-table-simple.test.js 28.0 KB
Newer Older
study夏羽's avatar
study夏羽 已提交
1
describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', () => {
Anne_LXM's avatar
Anne_LXM 已提交
2
	let page,perPage,segItems,roles;
study夏羽's avatar
study夏羽 已提交
3 4 5 6
	beforeAll(async () => {
		// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
		page = await program.reLaunch(
			'/pages/clientDB/permission-table-simple/permission-table-simple')
A
Anne_LXM 已提交
7 8 9 10 11 12 13
		page = await program.currentPage()
		await page.waitFor('view')
		perPage = await page.$('.page')
		//头部操作控制条
		segItems = await perPage.$$('.segmented-control__item')
		//底部角色控制条
		roles = await perPage.$$('.roles-item')
A
Anne_LXM 已提交
14
	})
study夏羽's avatar
study夏羽 已提交
15 16 17 18
	it('创建--未登陆', async () => {
		//点击创建
		await segItems[0].tap()
		await roles[0].tap()
A
Anne_LXM 已提交
19
		const start = Date.now()
study夏羽's avatar
study夏羽 已提交
20
		const createUnlogin = await page.waitFor(async () => {
A
Anne_LXM 已提交
21 22 23 24
			if(Date.now() - start > 4000){
				console.warn('连接服务器超时')
				return true
			}
study夏羽's avatar
study夏羽 已提交
25 26 27 28 29 30
			const createUnlogintIndex = await page.data('typeIndex')
			const createUnloginRole = await page.data('currentRole')
			return createUnlogintIndex === 0 && createUnloginRole === 0
		})
		console.log(createUnlogin, "创建--未登陆");
		if (createUnlogin) {
A
Anne_LXM 已提交
31
			// 允许任何角色创建本表
32
			const createA = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
33 34 35
				"type": "create",
				"index": 0
			})
A
Anne_LXM 已提交
36
			console.log('createA: ',createA);
A
Anne_LXM 已提交
37
			expect(createA.id).toHaveLength(24)
A
Anne_LXM 已提交
38
			
39 40
			// 禁止任何角色创建,管理员除外
			const createB = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
41 42 43
				"type": "create",
				"index": 1
			})
A
Anne_LXM 已提交
44
			console.log('createB: ',createB);
45 46 47
			
			// 需要登录后
			const createC = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
48 49 50
				"type": "create",
				"index": 2
			})
51 52 53
			
			// 限审核员角色创建
			const createD = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
54 55 56 57
				"type": "create",
				"index": 5
			})

58 59
			// 请求同时必须同时附带执行一个action云函数,如未触发该action则权限验证失败
			const createE = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
60 61 62
				"type": "create",
				"index": 6
			})
63 64 65
			
			// 附带执行一个action云函数
			const createAction = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
66 67 68 69
				"type": "create",
				"index": 6,
				"action": "add_view_count"
			})
Anne_LXM's avatar
Anne_LXM 已提交
70
			console.log('createAction: ',createAction);
A
Anne_LXM 已提交
71
			expect(createAction.id).toHaveLength(24)
study夏羽's avatar
study夏羽 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
		}
	})

	it('读取--未登陆', async () => {
		await segItems[1].tap()
		await roles[0].tap()

		const readUnlogin = await page.waitFor(async () => {
			const readUnloginIndex = await page.data('typeIndex')
			const readUnloginRole = await page.data('currentRole')
			return readUnloginIndex === 1 && readUnloginRole === 0
		})
		//console.log(readUnlogin, '读取--未登陆');

		if (readUnlogin) {
A
Anne_LXM 已提交
87
			// 含义解释:允许任何角色【读取】
88
			const readA = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
89 90 91
				"type": "read",
				"index": 0
			})
A
Anne_LXM 已提交
92
			console.log('readA: ',readA);
A
Anne_LXM 已提交
93
			expect(readA.data.length).toBeGreaterThanOrEqual(1)
A
Anne_LXM 已提交
94 95
			
			// 禁止任何角色读取
96
			const readB = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
97 98 99
				"type": "read",
				"index": 1
			})
100 101 102
			
			// 需登录后读取
			const readC = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
103 104 105
				"type": "read",
				"index": 2
			})
A
Anne_LXM 已提交
106
			
107 108
			// 只能读取自己创建的数据,先创建数据
			const readD = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
109 110 111
				"type": "create",
				"index": 3
			})
112 113 114
			
			// 只能读取自己创建的数据
			const readE = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
115 116 117 118 119
				"type": "read",
				"index": 3,
				"where": "uid == $env.uid"
			})

120 121
			// 读取全表数据
			const readF = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
122 123 124
				"type": "read",
				"index": 3
			})
Anne_LXM's avatar
Anne_LXM 已提交
125
			console.log('readF: ',readF);
126 127 128 129
			
			
			// 只能读取1分钟内创建的数据,先创建数据
			const readG = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
130 131 132
				"type": "create",
				"index": 4
			})
133 134 135
			
			// 只能读取1分钟内创建的数据
			const readH = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
136 137 138
				"type": "read",
				"index": 4,
				"where": "create_time > 1613541303576"
139
				})
A
Anne_LXM 已提交
140
			// console.log('readH: ',readH);
141 142 143 144
			
			
			// 读取全表数据
			const readI =await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
145 146 147
				"type": "read",
				"index": 4
			})
A
Anne_LXM 已提交
148
			// console.log('readI: ',readI);
149
			
A
Anne_LXM 已提交
150
			// 限审核员读取
151
			const readJ = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
152 153 154 155
				"type": "create",
				"index": 5
			})

156 157
			// 请求同时必须同时附带执行一个action云函数,如未触发该action则权限验证失败 读取全表数据
			const readK = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
158 159 160
				"type": "create",
				"index": 6
			})
161 162
			
			// 执行一个action云函数
A
Anne_LXM 已提交
163
			const actionRead = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
164 165 166 167
				"type": "read",
				"index": 6,
				"action": "add_view_count"
			})
A
Anne_LXM 已提交
168
			console.log('actionRead:--- ',actionRead);
A
Anne_LXM 已提交
169
			// expect(actionRead.data.length).toBeGreaterThanOrEqual(1)
study夏羽's avatar
study夏羽 已提交
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
		}

	})

	it('更新--未登陆', async () => {
		await segItems[2].tap()
		await roles[0].tap()

		const updateUnlogin = await page.waitFor(async () => {
			const updateUnloginIndex = await page.data('typeIndex')
			const updateUnloginRole = await page.data('currentRole')
			return updateUnloginIndex === 2 && updateUnloginRole === 0
		})
		//console.log(updateUnlogin, '更新--未登陆');

		if (updateUnlogin) {
186 187
			// 允许任何角色更新此表
			const updateA = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
188 189 190
				"type": "update",
				"index": 0
			})
A
Anne_LXM 已提交
191
			console.log('updateA:--- ',updateA);
Anne_LXM's avatar
Anne_LXM 已提交
192
			expect(updateA.updated).toBeGreaterThanOrEqual(1)
193 194 195
			
			// 禁止任何角色更新,管理员除外
			const updateB = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
196 197 198
				"type": "update",
				"index": 1
			})
199 200 201
			
			// 需要登录后
			const updateC = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
202 203 204
				"type": "update",
				"index": 2
			})
205 206 207
			
			// 只能更新自己创建的数据,先创建数据
			const updateD = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
208 209 210
				"type": "create",
				"index": 3
			})
211 212 213
			
			// 只能更新自己创建的数据
			const updateE = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
214 215 216 217 218
				"type": "update",
				"index": 3,
				"where": "uid == $env.uid"
			})

219 220
			//更新全表数据表
			const updateF = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
221 222 223
				"type": "update",
				"index": 3
			})
A
Anne_LXM 已提交
224
			console.log('updateF:--- ',updateF);
A
Anne_LXM 已提交
225
			// expect(updateF.updated).toBe(0)
study夏羽's avatar
study夏羽 已提交
226

227 228
			// 只更新1分钟内创建的数据,先创建数据
			const updateG = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
229 230 231 232
				"type": "create",
				"index": 4
			})

233 234
			// 只更新1分钟内创建的数据
			const updateH = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
235 236 237 238
				"type": "update",
				"index": 4,
				"where": "create_time > 1613546251521"
			})
A
Anne_LXM 已提交
239
			// console.log('updateH:------------------ ',updateH);
A
Anne_LXM 已提交
240
			// expect(updateH.result.updated).toBe(0)
241 242 243
			
			// 更新全表数据
			const updateI = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
244 245 246
				"type": "update",
				"index": 4
			})
A
Anne_LXM 已提交
247 248
			console.log('updateI:--- ',updateI);
			// expect(updateI.updated).toBe(0)
study夏羽's avatar
study夏羽 已提交
249

250 251
			//限审核员更新全表数据
			const updateJ = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
252 253 254
				"type": "update",
				"index": 5
			})
255 256 257
			
			// 更新全表 请求同时必须同时附带执行一个action云函数
			const updateK = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
258 259 260 261
				"type": "update",
				"index": 6
			})

262 263
			// 执行一个action云函数
			const updateAction = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
264 265 266 267
				"type": "update",
				"index": 6,
				"action": "add_view_count"
			})
A
Anne_LXM 已提交
268
			console.log('updateAction:--- ',updateAction);
A
Anne_LXM 已提交
269
			// expect(updateAction.updated).toBeGreaterThanOrEqual(1)
study夏羽's avatar
study夏羽 已提交
270 271 272 273 274 275 276 277 278 279 280 281 282
		}

	})

	it('删除--未登陆', async () => {
		await segItems[3].tap()
		await roles[0].tap()

		const deleteUnlogin = await page.waitFor(async () => {
			const deleteUnloginIndex = await page.data('typeIndex')
			const deleteUnloginRole = await page.data('currentRole')
			return deleteUnloginIndex === 3 && deleteUnloginRole === 0
		})
283
		console.log(deleteUnlogin, '删除--未登陆');
study夏羽's avatar
study夏羽 已提交
284

285 286
		// 允许任何角色删除全表
		const deleteA = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
287 288 289
			"type": "delete",
			"index": 0
		})
A
Anne_LXM 已提交
290
		console.log("deleteA---",deleteA);
Anne_LXM's avatar
Anne_LXM 已提交
291
		expect(deleteA.deleted).toBeGreaterThanOrEqual(1)
292 293 294
		
		// 禁止任何角色删除,管理员除外
		const deleteB = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
295 296 297
			"type": "delete",
			"index": 1
		})
298 299 300
		
		// 需登录后可删除
		const deleteC = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
301 302 303
			"type": "delete",
			"index": 2
		})
304 305 306
		
		// 只能删除自己创建的数据,先创建数据
		const deleteD = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
307 308 309
			"type": "create",
			"index": 3
		})
310 311 312
		
		// 只能删除自己创建的数据
		const deleteE = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
313 314 315 316 317
			"type": "delete",
			"index": 3,
			"where": "uid == $env.uid"
		})

318 319
		// 删除全表数据
		const deleteF = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
320 321 322
			"type": "delete",
			"index": 3
		})
A
Anne_LXM 已提交
323
		console.log('deleteF: ---',deleteF);
A
Anne_LXM 已提交
324
		// expect(deleteF.deleted).toBe(0)
study夏羽's avatar
study夏羽 已提交
325

326 327 328
		// 只更新1分钟内创建的数据,先创建数据
		const deleteG = await page.callMethod('myFn', {
			"type": "create",
study夏羽's avatar
study夏羽 已提交
329 330
			"index": 4
		})
A
Anne_LXM 已提交
331
		
332
		// 只更新1分钟内创建的数据
A
Anne_LXM 已提交
333 334 335 336 337
		await page.callMethod('myFn', {
			"type": "delete",
			"index": 4,
			"where": "create_time > 1613546644107"
		})
338 339
		
		// 删除全表数据
A
Anne_LXM 已提交
340 341 342 343
		await page.callMethod('myFn', {
			"type": "delete",
			"index": 4
		})
study夏羽's avatar
study夏羽 已提交
344

345 346
		// 删除全表 仅审核员
		const deleteH = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
347 348 349
			"type": "delete",
			"index": 5
		})
350 351 352
		
		// 更新全表 请求同时必须同时附带执行一个action云函数
		const deleteI = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
353 354 355 356
			"type": "delete",
			"index": 6
		})

357 358
		// 附带执行一个action云函数
		const deleteAction = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
359 360 361 362
			"type": "delete",
			"index": 6,
			"action": "add_view_count"
		})
A
Anne_LXM 已提交
363
		console.log('deleteAction: ---',deleteAction);
A
Anne_LXM 已提交
364
		// expect(deleteAction.deleted).toBeGreaterThanOrEqual(1)
study夏羽's avatar
study夏羽 已提交
365 366 367 368 369 370 371 372 373 374 375 376
	})

	it('创建--用户', async () => {
		await segItems[0].tap()
		await roles[1].tap()
		const createUser = await page.waitFor(async () => {
			const typeIndex = await page.data('typeIndex')
			const currentRole = await page.data('currentRole')
			return typeIndex === 0 && currentRole == 'user'
		})
		console.log(createUser, '创建--用户');

377 378
		// 任何角色可创建
		const createUserA = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
379 380 381
			"type": "create",
			"index": 0
		})
A
Anne_LXM 已提交
382
		expect(createUserA.id).toHaveLength(24)
383 384 385
		
		// 禁止任何角色创建,仅管理员
		const createUserB = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
386 387 388
			"type": "create",
			"index": 1
		})
389 390 391
		
		// 已登录 可创建
		const createUserC = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
392 393 394
			"type": "create",
			"index": 2
		})
A
Anne_LXM 已提交
395
		expect(createUserC.id).toHaveLength(24)
study夏羽's avatar
study夏羽 已提交
396

397 398
		// 仅审核员可创建
		const createUserD = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
399 400 401 402
			"type": "create",
			"index": 5
		})

403 404
		// 请求同时必须同时附带执行一个action云函数,如未触发该action则权限验证失败
		const createUserE = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
405 406 407
			"type": "create",
			"index": 6
		})
408 409 410
		
		// 附带执行一个action云函数
		const createUserF = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
411 412 413 414
			"type": "create",
			"index": 6,
			"action": "add_view_count"
		})
A
Anne_LXM 已提交
415
		expect(createUserF.id).toHaveLength(24)
study夏羽's avatar
study夏羽 已提交
416 417 418 419 420 421 422 423 424 425 426 427

	})

	it('读取--用户', async () => {
		await segItems[1].tap()
		await roles[1].tap()

		const readUser = await page.waitFor(async () => {
			const readUserIndex = await page.data('typeIndex')
			const readUserRole = await page.data('currentRole')
			return readUserIndex === 1 && readUserRole == 'user'
		})
428
		console.log(readUser, '读取--用户');
study夏羽's avatar
study夏羽 已提交
429

430 431
		// 任何人可读取
		const readUserA = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
432 433 434
			"type": "read",
			"index": 0
		})
A
Anne_LXM 已提交
435 436
		// console.log('readUserA: ',readUserA);
		expect(readUserA.errCode).toBe(0)
A
Anne_LXM 已提交
437
		// expect(readUserA.result.data.length).toBeGreaterThan(0)
438 439 440
		
		// 仅管理员可读
		const readUserB = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
441 442 443
			"type": "read",
			"index": 1
		})
444 445 446
		
		// 登录后可读取
		const readUserC = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
447 448 449
			"type": "read",
			"index": 2
		})
A
Anne_LXM 已提交
450
		// console.log('readUserC: ',readUserC);
A
Anne_LXM 已提交
451
		expect(readUserC.data.length).toBeGreaterThan(0)
452 453 454
		
		// 只能读取自己创建的数据,先创建数据
		const readUserD = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
455 456 457
			"type": "create",
			"index": 3
		})
A
Anne_LXM 已提交
458
		expect(readUserD.id).toHaveLength(24)
459 460 461
		
		// 只能读取自己创建的数据
		const readUserE = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
462 463 464 465
			"type": "read",
			"index": 3,
			"where": "uid == $env.uid"
		})
A
Anne_LXM 已提交
466
		// console.log('readUserE: ',readUserE);
A
Anne_LXM 已提交
467
		expect(readUserE.data.length).toBeGreaterThan(0)
468 469 470
		
		// 读取全表数据
		const readUserF = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
471 472 473
			"type": "read",
			"index": 3
		})
Anne_LXM's avatar
Anne_LXM 已提交
474
		console.log('readUserF:---------- ',readUserF);
A
Anne_LXM 已提交
475
		expect(readUserF.data.length).toBeGreaterThan(0)
476 477 478
		
		// 只读取1分钟内创建的数据,先创建数据
		const readUserG = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
479 480 481
			"type": "create",
			"index": 4
		})
A
Anne_LXM 已提交
482
		expect(readUserG.id).toHaveLength(24)
483 484 485
		
		// 只读取1分钟内创建的数据
		const readUserH = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
486 487 488 489
			"type": "read",
			"index": 4,
			"where": "create_time > 1613541303576"
		})
A
Anne_LXM 已提交
490
		// console.log('readUserH: ',readUserH);
A
Anne_LXM 已提交
491
		expect(readUserH.data.length).toBeGreaterThan(0)
492 493 494
		
		// 读取全表数据
		const readUserI = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
495 496 497
			"type": "read",
			"index": 4
		})
A
Anne_LXM 已提交
498
		// console.log('readUserI: ',readUserI);
A
Anne_LXM 已提交
499
		expect(readUserI.data.length).toBeGreaterThanOrEqual(1)
500 501 502
		
		// 仅审核员读取全表数据
		const readUserJ = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
503 504 505 506
			"type": "read",
			"index": 5
		})

507 508
		// 请求同时必须同时附带执行一个action云函数,如未触发该action则权限验证失败
		const readUserK = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
509 510 511
			"type": "read",
			"index": 6
		})
512 513 514
		
		// 执行一个action云函数
		const readUserO = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
515 516 517 518
			"type": "read",
			"index": 6,
			"action": "add_view_count"
		})
A
Anne_LXM 已提交
519
		// console.log('readUserO: ',readUserO);
A
Anne_LXM 已提交
520
		// expect(readUserO.data.length).toBeGreaterThan(0)
A
Anne_LXM 已提交
521
		expect(readUserO.errCode).toBe(0)
study夏羽's avatar
study夏羽 已提交
522 523

	})
A
Anne_LXM 已提交
524
	
study夏羽's avatar
study夏羽 已提交
525 526 527 528 529 530 531 532 533 534 535
	it('更新--用户', async () => {
		await segItems[2].tap()
		await roles[1].tap()

		const updateUser = await page.waitFor(async () => {
			const updateUserIndex = await page.data('typeIndex')
			const updateUserRole = await page.data('currentRole')
			return updateUserIndex === 2 && updateUserRole == 'user'
		})
		console.log(updateUser, '更新--用户');

536 537
		// 允许任何人更新
		const updateUserA = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
538 539 540
			"type": "update",
			"index": 0
		})
A
Anne_LXM 已提交
541 542
		console.log('updateUserA: ',updateUserA);
		// expect(updateUserA.updated).toBeGreaterThanOrEqual(1)
543 544 545
		
		// 禁止任何人更新 除管理员
		const updateUserB = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
546 547 548
			"type": "update",
			"index": 1
		})
549 550 551
		
		// 需要登录后更新
		const updateUserC = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
552 553 554
			"type": "update",
			"index": 2
		})
A
Anne_LXM 已提交
555
		expect(updateUserC.updated).toBeGreaterThanOrEqual(1)
556 557 558
		
		// 仅更新自己创建的数据 先创建数据
		const updateUserD = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
559 560 561
			"type": "create",
			"index": 3
		})
A
Anne_LXM 已提交
562
		expect(updateUserD.id).toHaveLength(24)
study夏羽's avatar
study夏羽 已提交
563

564 565
		// 仅更新自己创建的数据 
		const updateUserE = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
566 567 568 569
			"type": "update",
			"index": 3,
			"where": "uid == $env.uid"
		})
A
Anne_LXM 已提交
570
		expect(updateUserE.updated).toBeGreaterThanOrEqual(1)
571 572 573
		
		// 更新全部数据
		const updateUserF = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
574 575 576
			"type": "update",
			"index": 3
		})
Anne_LXM's avatar
Anne_LXM 已提交
577 578
		console.log('updateUserF: ------------------',updateUserF);
		// expect(updateUserF.updated).toBeGreaterThanOrEqual(1)
579 580 581
		
		// 只更新1分钟内创建的数据 先创建数据
		const updateUserG = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
582 583 584
			"type": "create",
			"index": 4
		})
A
Anne_LXM 已提交
585
		expect(updateUserG.id).toHaveLength(24)
study夏羽's avatar
study夏羽 已提交
586

587 588
		// 只更新1分钟内创建的数据
		const updateUserH = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
589 590 591 592
			"type": "update",
			"index": 4,
			"where": "create_time > 1613546251521"
		})
A
Anne_LXM 已提交
593
		expect(updateUserH.updated).toBeGreaterThanOrEqual(1)
594 595 596
		
		// 更新全部数据
		const updateUserI = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
597 598 599
			"type": "update",
			"index": 4
		})
A
Anne_LXM 已提交
600
		expect(updateUserI.updated).toBeGreaterThanOrEqual(1)
601 602 603
		
		// 限审核员更新数据
		const updateUserJ = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
604 605 606
			"type": "update",
			"index": 5
		})
607 608 609
		
		// 请求同时必须同时附带执行一个action云函数,如未触发该action则权限验证失败
		const updateUserK = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
610 611 612 613
			"type": "update",
			"index": 6
		})

614 615
		// 请求同时必须同时附带执行一个action云函数
		const updateUserAction = await page.callMethod('myFn', {
study夏羽's avatar
study夏羽 已提交
616 617 618 619
			"type": "update",
			"index": 6,
			"action": "add_view_count"
		})
A
Anne_LXM 已提交
620
		// console.log('updateUserAction: ',updateUserAction);
A
Anne_LXM 已提交
621
		expect(updateUserAction.updated).toBeGreaterThanOrEqual(1)
study夏羽's avatar
study夏羽 已提交
622 623 624 625 626 627 628 629 630 631 632
	})

	it('删除--用户', async () => {
		await segItems[3].tap()
		await roles[1].tap()

		const deleteUser = await page.waitFor(async () => {
			const deleteUserIndex = await page.data('typeIndex')
			const deleteUserRole = await page.data('currentRole')
			return deleteUserIndex === 3 && deleteUserRole == 'user'
		})
633
		console.log(deleteUser, '删除--用户');
study夏羽's avatar
study夏羽 已提交
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 0
		})

		const deleteUserA = await page.callMethod('myFn', {
			"type": "delete",
			"index": 1
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 2
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 3
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 3,
			"where": "uid == $env.uid"
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 3
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 4
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 4,
			"where": "create_time > 1613547725091"
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 4
		})

		const deleteUserB = await page.callMethod('myFn', {
			"type": "delete",
			"index": 5
		})

		const deleteUserC = await page.callMethod('myFn', {
			"type": "delete",
			"index": 6
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 6,
			"action": "add_view_count"
		})

	})

	it('创建--审核员Auditor', async () => {
		await segItems[0].tap()
		await roles[2].tap()

		const createAuditor = await page.waitFor(async () => {
			const createAuditorIndex = await page.data('typeIndex')
			const createAuditorRole = await page.data('currentRole')
			return createAuditorIndex === 0 && createAuditorRole == 'auditor'
		})
		//console.log(createAuditor, '创建--审核员');
		await page.callMethod('myFn', {
			"type": "create",
			"index": 0
		})

		const createAuditorA = await page.callMethod('myFn', {
			"type": "create",
			"index": 1
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 2
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 5
		})

		const createAuditorB = await page.callMethod('myFn', {
			"type": "create",
			"index": 6
		})
		// expect(createAuditorB.id).toBeTruthy()
		// expect(createAuditorB).toBe('[permission-test-7.create]权限校验未通过')

		await page.callMethod('myFn', {
			"type": "create",
			"index": 6,
			"action": "add_view_count"
		})

	})

	it('读取--审核员', async () => {
		await segItems[1].tap()
		await roles[2].tap()

		const readAuditor = await page.waitFor(async () => {
			const readAuditorIndex = await page.data('typeIndex')
			const readAuditorRole = await page.data('currentRole')
			return readAuditorIndex === 1 && readAuditorRole == 'auditor'
		})
		console.log(readAuditor, '读取--审核员');

		await page.callMethod('myFn', {
			"type": "read",
			"index": 0
		})

		const readAuditorA = await page.callMethod('myFn', {
			"type": "read",
			"index": 1
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 2
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 3
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 3,
			"where": "uid == $env.uid"
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 3
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 4
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 4,
			"where": "create_time > 1613541303576"
		})


		await page.callMethod('myFn', {
			"type": "read",
			"index": 4
		})


		await page.callMethod('myFn', {
			"type": "read",
			"index": 5
		})


		const readAuditorB = await page.callMethod('myFn', {
			"type": "read",
			"index": 6
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 6,
			"action": "add_view_count"
		})
	})

	it('更新--审核员', async () => {
		await segItems[2].tap()
		await roles[2].tap()

		const updateAuditor = await page.waitFor(async () => {
			const updateAuditorIndex = await page.data('typeIndex')
			const updateAuditorRole = await page.data('currentRole')
			return updateAuditorIndex === 2 && updateAuditorRole == 'auditor'
		})
		console.log(updateAuditor, '更新--审核员');

		await page.callMethod('myFn', {
			"type": "update",
			"index": 0
		})

		const updateAuditorA = await page.callMethod('myFn', {
			"type": "update",
			"index": 1
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 2
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 3
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 3,
			"where": "uid == $env.uid"
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 3
		})


		await page.callMethod('myFn', {
			"type": "create",
			"index": 4
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 4,
			"where": "create_time > 1613546251521"
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 4
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 5
		})

		const updateAuditorB = await page.callMethod('myFn', {
			"type": "update",
			"index": 6
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 6,
			"action": "add_view_count"
		})
	})

	it('删除--审核员', async () => {
		await segItems[3].tap()
		await roles[2].tap()

		const deleteAuditor = await page.waitFor(async () => {
			const deleteAuditorIndex = await page.data('typeIndex')
			const deleteAuditorRole = await page.data('currentRole')
			return deleteAuditorIndex === 3 && deleteAuditorRole == 'auditor'
		})
		//console.log(deleteAuditor, '删除--审核员');

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 0
		})

		const deleteAuditorA = await page.callMethod('myFn', {
			"type": "delete",
			"index": 1
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 2
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 3
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 3,
			"where": "uid == $env.uid"
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 3
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 4
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 4,
			"where": "create_time > 1613547725091"
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 4
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 5
		})

		const deleteAuditorB = await page.callMethod('myFn', {
			"type": "delete",
			"index": 6
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 6,
			"action": "add_view_count"
		})

	})

	it('创建--管理员admin', async () => {
		await segItems[0].tap()
		await roles[3].tap()

		const createAdmin = await page.waitFor(async () => {
			const createAdminIndex = await page.data('typeIndex')
			const createAdminRole = await page.data('currentRole')
			return createAdminIndex === 0 && createAdminRole == 'admin'
		})
		console.log(createAdmin, '创建--管理员');

		await page.callMethod('myFn', {
			"type": "create",
			"index": 0
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 1
		})


		await page.callMethod('myFn', {
			"type": "create",
			"index": 2
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 5
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 6
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 6,
			"action": "add_view_count"
		})

	})

	it('读取--管理员', async () => {
		await segItems[1].tap()
		await roles[3].tap()
		const readAdmin = await page.waitFor(async () => {
			const readAdminIndex = await page.data('typeIndex')
			const readAdminRole = await page.data('currentRole')
			return readAdminIndex === 1 && readAdminRole == 'admin'
		})
		//console.log(readAdmin, '读取--管理员');
		await page.callMethod('myFn', {
			"type": "read",
			"index": 0
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 1
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 2
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 3
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 3,
			"where": "uid == $env.uid"
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 3
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 4
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 4,
			"where": "create_time > 1613541303576"
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 4
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 5
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 6
		})

		await page.callMethod('myFn', {
			"type": "read",
			"index": 6,
			"action": "add_view_count"
		})
	})

	it('更新--管理员', async () => {
		await segItems[2].tap()
		await roles[3].tap()

		const updateAdmin = await page.waitFor(async () => {
			const updateAdminIndex = await page.data('typeIndex')
			const updateAdminRole = await page.data('currentRole')
			return updateAdminIndex === 2 && updateAdminRole == 'admin'
		})
		//console.log(updateAdmin, '更新--管理员');

		await page.callMethod('myFn', {
			"type": "update",
			"index": 0
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 1
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 2
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 3
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 3,
			"where": "uid == $env.uid"
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 3
		})


		await page.callMethod('myFn', {
			"type": "create",
			"index": 4
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 4,
			"where": "create_time > 1613546251521"
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 4
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 5
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 6
		})

		await page.callMethod('myFn', {
			"type": "update",
			"index": 6,
			"action": "add_view_count"
		})
	})

	it('删除--管理员', async () => {
		await segItems[3].tap()
		await roles[3].tap()

		const deleteAdmin = await page.waitFor(async () => {
			const deleteAdminIndex = await page.data('typeIndex')
			const deleteAdminRole = await page.data('currentRole')
			return deleteAdminIndex === 3 && deleteAdminRole === 'admin'
		})
		//console.log(deleteAdmin, '删除--管理员');
		await page.callMethod('myFn', {
			"type": "delete",
			"index": 0
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 1
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 2
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 3
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 3,
			"where": "create_time > 1613572491536"
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 3
		})

		await page.callMethod('myFn', {
			"type": "create",
			"index": 4
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 4,
			"where": "create_time > 1613547725091"
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 4
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 5
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 6
		})

		await page.callMethod('myFn', {
			"type": "delete",
			"index": 6,
			"action": "add_view_count"
		})

	})

})