MCPcopy
hub / github.com/simstudioai/sim / queueWhereResponses

Function queueWhereResponses

apps/sim/lib/invitations/direct-grant.test.ts:59–75  ·  view source on GitHub ↗

* Drives `db.select().from().where()` results in call order. Both an awaited * `where()` and a chained `.limit()` resolve to the same per-call value.

(responses: unknown[][])

Source from the content-addressed store, hash-verified

57 * `where()` and a chained `.limit()` resolve to the same per-call value.
58 */
59function queueWhereResponses(responses: unknown[][]) {
60 const queue = [...responses]
61 dbChainMockFns.where.mockImplementation(() => {
62 const result = queue.shift() ?? []
63 const thenable = Promise.resolve(result) as Promise<unknown[]> & {
64 limit: ReturnType<typeof vi.fn>
65 orderBy: ReturnType<typeof vi.fn>
66 returning: ReturnType<typeof vi.fn>
67 groupBy: ReturnType<typeof vi.fn>
68 }
69 thenable.limit = vi.fn(() => Promise.resolve(result))
70 thenable.orderBy = vi.fn(() => Promise.resolve(result))
71 thenable.returning = vi.fn(() => Promise.resolve(result))
72 thenable.groupBy = vi.fn(() => Promise.resolve(result))
73 return thenable as ReturnType<typeof dbChainMockFns.where>
74 })
75}
76
77const baseInput = {
78 userId: 'user-2',

Callers 1

Calls 2

shiftMethod · 0.80
resolveMethod · 0.65

Tested by

no test coverage detected