|
13 | 13 | */ |
14 | 14 |
|
15 | 15 | import { describe, expect, it, vi } from 'vitest'; |
| 16 | +// Pay the lazy `@objectstack/lint` load during collection, not inside a clocked case. |
| 17 | +import '@objectstack/lint'; |
16 | 18 | import { |
17 | 19 | assertEngineDeleteDispatch, |
18 | 20 | assertEngineUpdateDispatch, |
@@ -103,15 +105,11 @@ function makeStubEngine() { |
103 | 105 | assertEngineFindOnePredicate(table, opts); |
104 | 106 | return findRow(table, opts.where)?.row ?? null; |
105 | 107 | }, |
106 | | - async find(table: string, opts: { where: Record<string, unknown> }) { |
107 | | - return Array.from(tableOf(table).values()).filter((r) => { |
108 | | - if (opts.where.type && !whereValueMatches(r.type, opts.where.type)) return false; |
109 | | - if (opts.where.name !== undefined && r.name !== opts.where.name) return false; |
110 | | - if (opts.where.organization_id !== undefined |
111 | | - && r.organization_id !== opts.where.organization_id) return false; |
112 | | - if (opts.where.state && r.state !== opts.where.state) return false; |
113 | | - return true; |
114 | | - }); |
| 108 | + async find(table: string, opts: { where: Record<string, unknown>; limit?: number }) { |
| 109 | + // Every stated key of the `where` is matched (`$in` or equality), then the bound. |
| 110 | + const matched = Array.from(tableOf(table).values()).filter((r) => |
| 111 | + Object.entries(opts.where).every(([k, v]) => v === undefined || whereValueMatches(r[k], v))); |
| 112 | + return typeof opts?.limit === 'number' ? matched.slice(0, opts.limit) : matched; |
115 | 113 | }, |
116 | 114 | async insert(table: string, data: Record<string, unknown>) { |
117 | 115 | nextId += 1; |
@@ -225,10 +223,10 @@ describe('addAuthoringGate: a gate beside the owner gate (#37766)', () => { |
225 | 223 | const { protocol } = makeProtocolOn(); |
226 | 224 | protocol.addAuthoringGate('object', () => { |
227 | 225 | const err: any = new Error('refused'); |
228 | | - err.code = 'VALIDATION_FAILED'; err.status = 422; |
| 226 | + err.code = 'VALIDATION_FAILED'; err.status = 400; |
229 | 227 | throw err; |
230 | 228 | }); |
231 | | - await expect(protocol.runAuthoringGate(gateEvent())).rejects.toMatchObject({ code: 'VALIDATION_FAILED', status: 422 }); |
| 229 | + await expect(protocol.runAuthoringGate(gateEvent())).rejects.toMatchObject({ code: 'VALIDATION_FAILED', status: 400 }); |
232 | 230 | }); |
233 | 231 |
|
234 | 232 | it('a throw of the owner gate stops the write before any added gate runs', async () => { |
@@ -268,11 +266,11 @@ describe('addAuthoringGate through the save and publish doors (#37766)', () => { |
268 | 266 | const { protocol, rows } = makeProtocolOn(); |
269 | 267 | protocol.addAuthoringGate('flow', (ctx: any) => { |
270 | 268 | if (ctx.state !== 'active') return; |
271 | | - throw Object.assign(new Error('VALIDATION_FAILED: refused'), { code: 'VALIDATION_FAILED', status: 422 }); |
| 269 | + throw Object.assign(new Error('VALIDATION_FAILED: refused'), { code: 'VALIDATION_FAILED', status: 400 }); |
272 | 270 | }); |
273 | 271 | await protocol.saveMetaItem({ type: 'flow', name: 'leave_approval', item: validApprovalFlow(), mode: 'draft' }); |
274 | 272 | const err = await protocol.publishMetaItem({ type: 'flow', name: 'leave_approval' }).catch((e: any) => e); |
275 | | - expect(err).toMatchObject({ code: 'VALIDATION_FAILED', status: 422 }); |
| 273 | + expect(err).toMatchObject({ code: 'VALIDATION_FAILED', status: 400 }); |
276 | 274 | expect(flowRows(rows).map((r) => r.state), 'no active row').not.toContain('active'); |
277 | 275 | }); |
278 | 276 |
|
|
0 commit comments