Fix viewV2.spec.ts

This commit is contained in:
Sam Rose 2025-03-04 17:08:20 +00:00
parent 51301b3842
commit 3e17fa186c
No known key found for this signature in database
1 changed files with 25 additions and 18 deletions

View File

@ -2826,35 +2826,42 @@ if (descriptions.length) {
return total
}
async function expectRowUsage(
async function expectRowUsage<T>(
expected: number,
f: () => Promise<void>
) {
const before = await getRowUsage()
await f()
const after = await getRowUsage()
const usage = after - before
expect(usage).toBe(expected)
f: () => Promise<T>
): Promise<T> {
return await quotas.withEnabled(async () => {
const before = await getRowUsage()
const result = await f()
const after = await getRowUsage()
const usage = after - before
expect(usage).toBe(expected)
return result
})
}
it("should be able to delete a row", async () => {
const createdRow = await config.api.row.save(table._id!, {})
await expectRowUsage(isInternal ? 0 : -1, async () => {
await config.api.row.bulkDelete(view.id, { rows: [createdRow] })
})
const createdRow = await expectRowUsage(isInternal ? 1 : 0, () =>
config.api.row.save(table._id!, {})
)
await expectRowUsage(isInternal ? -1 : 0, () =>
config.api.row.bulkDelete(view.id, { rows: [createdRow] })
)
await config.api.row.get(table._id!, createdRow._id!, {
status: 404,
})
})
it("should be able to delete multiple rows", async () => {
const rows = await Promise.all([
config.api.row.save(table._id!, {}),
config.api.row.save(table._id!, {}),
config.api.row.save(table._id!, {}),
])
const rows = await expectRowUsage(isInternal ? 3 : 0, async () => {
return [
await config.api.row.save(table._id!, {}),
await config.api.row.save(table._id!, {}),
await config.api.row.save(table._id!, {}),
]
})
await expectRowUsage(isInternal ? 0 : -2, async () => {
await expectRowUsage(isInternal ? -2 : 0, async () => {
await config.api.row.bulkDelete(view.id, {
rows: [rows[0], rows[2]],
})