Skip to content

Commit 1001923

Browse files
committed
reduce the number of context calls for delete access tests
1 parent 0cd6b37 commit 1001923

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

tests/api-tests/access.test.ts

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -322,20 +322,20 @@ describe(`Access (${dbProvider})`, () => {
322322

323323
test.concurrent(`list.access.${l.expect.type}.query: ${l.expect.query} for counting`, async () => {
324324
const { context } = await suite()
325-
const id = await seed(l.name, context)
325+
const ids = await seedMany(l.name, context)
326326

327327
// test list.access.*.query
328328
const count = await context.query[l.name].count({
329329
where: {
330330
id: {
331-
equals: id
331+
in: ids
332332
}
333333
}
334334
})
335335

336336
if (l.expect.query) {
337337
expect(count).not.toBe(null)
338-
expect(count).toBe(1)
338+
expect(count).toBe(ids.length)
339339
} else {
340340
expect(count).toBe(0)
341341
}
@@ -352,7 +352,7 @@ describe(`Access (${dbProvider})`, () => {
352352

353353
if (!l.expect.create) {
354354
const error = createPromise.catch((e: any) => e.message)
355-
await expect(error).resolves.toBe(`Access denied: You cannot create that ${l.name}`)
355+
expect(await error).toBe(`Access denied: You cannot create that ${l.name}`)
356356
return
357357
}
358358

@@ -382,7 +382,7 @@ describe(`Access (${dbProvider})`, () => {
382382

383383
if (!l.expect.create) {
384384
const error = createPromise.catch((e: any) => e.message)
385-
await expect(error).resolves.toBe(`Access denied: You cannot create that ${l.name}`)
385+
expect(await error).toBe(`Access denied: You cannot create that ${l.name}`)
386386
return
387387
}
388388

@@ -415,7 +415,7 @@ describe(`Access (${dbProvider})`, () => {
415415

416416
if (!l.expect.update) {
417417
const error = updatePromise.catch(e => e.message)
418-
await expect(error).resolves.toBe(`Access denied: You cannot update that ${l.name} - it may not exist`)
418+
expect(await error).toBe(`Access denied: You cannot update that ${l.name} - it may not exist`)
419419
return
420420
}
421421

@@ -450,7 +450,7 @@ describe(`Access (${dbProvider})`, () => {
450450

451451
if (!l.expect.update) {
452452
const error = updatePromise.catch(e => e.message)
453-
await expect(error).resolves.toBe(`Access denied: You cannot update that ${l.name} - it may not exist`)
453+
expect(await error).toBe(`Access denied: You cannot update that ${l.name} - it may not exist`)
454454
return
455455
}
456456

@@ -482,7 +482,7 @@ describe(`Access (${dbProvider})`, () => {
482482

483483
if (!l.expect.delete) {
484484
const error = deletePromise.catch(e => e.message)
485-
await expect(error).resolves.toBe(`Access denied: You cannot delete that ${l.name} - it may not exist`)
485+
expect(await error).resolves.toBe(`Access denied: You cannot delete that ${l.name} - it may not exist`)
486486
return
487487
}
488488

@@ -499,7 +499,7 @@ describe(`Access (${dbProvider})`, () => {
499499
}
500500
}
501501

502-
// sudo required, as we might not have read
502+
// sudo required, as we might not have query/read access
503503
const item_ = await context.sudo().db[l.name].findOne({ where: { id } })
504504
expect(item_).toBe(null)
505505
})
@@ -518,7 +518,7 @@ describe(`Access (${dbProvider})`, () => {
518518

519519
if (!l.expect.delete) {
520520
const error = deletePromise.catch(e => e.message)
521-
await expect(error).resolves.toBe(`Access denied: You cannot delete that ${l.name} - it may not exist`)
521+
expect(await error).resolves.toBe(`Access denied: You cannot delete that ${l.name} - it may not exist`)
522522
return
523523
}
524524

@@ -536,6 +536,16 @@ describe(`Access (${dbProvider})`, () => {
536536
}
537537
}
538538
}
539+
540+
// sudo required, as we might not have query/read access
541+
const items_ = await context.sudo().db[l.name].findMany({
542+
where: {
543+
id: {
544+
in: items.map(x => x.id)
545+
}
546+
}
547+
})
548+
expect(items_).toHaveLength(0)
539549
})
540550

541551
// field operations tests
@@ -632,7 +642,7 @@ describe(`Access (${dbProvider})`, () => {
632642
expect(item![f.name]).toBe(null)
633643
}
634644

635-
// sudo required, as we might not have read
645+
// sudo required, as we might not have query/read access
636646
const item_ = await context.sudo().db[l.name].findOne({ where: { id: item.id } })
637647
expect(item_![f.name]).toBe('foo')
638648
})
@@ -660,18 +670,24 @@ describe(`Access (${dbProvider})`, () => {
660670
expect(items).not.toBe(null)
661671
expect(items).toHaveLength(count)
662672

673+
// sudo required, as we might not have query/read access
674+
const items_ = await context.sudo().db[l.name].findMany({
675+
where: {
676+
id: {
677+
in: items.map(x => x.id)
678+
}
679+
}
680+
})
681+
663682
for (const item of items) {
664683
// test field.access.read
665684
expect(item).toHaveProperty(f.name)
666685
if (f.expect.read) {
667686
expect(item![f.name]).toBe('foo')
668687
} else {
669688
expect(item![f.name]).toBe(null)
689+
expect(items_.find(x => x.id === item.id)![f.name]).toBe('foo')
670690
}
671-
672-
// sudo required, as we might not have read
673-
const item_ = await context.sudo().db[l.name].findOne({ where: { id: item.id } })
674-
expect(item_![f.name]).toBe('foo')
675691
}
676692
})
677693
}
@@ -733,7 +749,7 @@ describe(`Access (${dbProvider})`, () => {
733749
// test field.access.update
734750
if (!f.expect.update) {
735751
const error = updatePromise.catch(e => e.message)
736-
await expect(error).resolves.toBe(`Access denied: You cannot update that ${l.name} - you cannot update the fields ["${f.name}"]`)
752+
expect(await error).toBe(`Access denied: You cannot update that ${l.name} - you cannot update the fields ["${f.name}"]`)
737753
return
738754
}
739755

0 commit comments

Comments
 (0)