Fix viewV2.spec.ts

This commit is contained in:
Sam Rose 2025-03-04 16:28:25 +00:00
parent 330790214b
commit 021667c7d9
No known key found for this signature in database
1 changed files with 15 additions and 10 deletions

View File

@ -2826,16 +2826,22 @@ if (descriptions.length) {
return total return total
} }
const assertRowUsage = async (expected: number) => { async function expectRowUsage(
const usage = await getRowUsage() expected: number,
f: () => Promise<void>
) {
const before = await getRowUsage()
await f()
const after = await getRowUsage()
const usage = after - before
expect(usage).toBe(expected) expect(usage).toBe(expected)
} }
it("should be able to delete a row", async () => { it("should be able to delete a row", async () => {
const createdRow = await config.api.row.save(table._id!, {}) const createdRow = await config.api.row.save(table._id!, {})
const rowUsage = await getRowUsage() await expectRowUsage(isInternal ? 0 : -1, async () => {
await config.api.row.bulkDelete(view.id, { rows: [createdRow] }) await config.api.row.bulkDelete(view.id, { rows: [createdRow] })
await assertRowUsage(isInternal ? rowUsage - 1 : rowUsage) })
await config.api.row.get(table._id!, createdRow._id!, { await config.api.row.get(table._id!, createdRow._id!, {
status: 404, status: 404,
}) })
@ -2847,13 +2853,12 @@ if (descriptions.length) {
config.api.row.save(table._id!, {}), config.api.row.save(table._id!, {}),
config.api.row.save(table._id!, {}), config.api.row.save(table._id!, {}),
]) ])
const rowUsage = await getRowUsage()
await expectRowUsage(isInternal ? 0 : -2, async () => {
await config.api.row.bulkDelete(view.id, { await config.api.row.bulkDelete(view.id, {
rows: [rows[0], rows[2]], rows: [rows[0], rows[2]],
}) })
})
await assertRowUsage(isInternal ? rowUsage - 2 : rowUsage)
await config.api.row.get(table._id!, rows[0]._id!, { await config.api.row.get(table._id!, rows[0]._id!, {
status: 404, status: 404,