test: add tests and questions service tests
Made-with: Cursor
This commit is contained in:
@@ -24,6 +24,40 @@ export function selectChain(resolveAtLimit: unknown[] = []) {
|
||||
};
|
||||
}
|
||||
|
||||
/** Build a select chain for .from().where().orderBy() - orderBy is terminal */
|
||||
export function selectChainOrdered(resolveAtOrderBy: unknown[] = []) {
|
||||
const orderByThenable = {
|
||||
then: (resolve: (v: unknown) => void) => resolve(resolveAtOrderBy),
|
||||
};
|
||||
return {
|
||||
from: vi.fn().mockReturnValue({
|
||||
where: vi.fn().mockReturnValue({
|
||||
orderBy: vi.fn().mockReturnValue(orderByThenable),
|
||||
}),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
/** Build a select chain for .from().where() with no orderBy - used by select({...}).from() */
|
||||
export function selectChainSimple(resolveRows: unknown[] = []) {
|
||||
const thenable = { then: (resolve: (v: unknown) => void) => resolve(resolveRows) };
|
||||
return {
|
||||
from: vi.fn().mockReturnValue({
|
||||
where: vi.fn().mockReturnValue(thenable),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
/** Build a select chain for .from().where() - where is terminal (no orderBy/limit) */
|
||||
export function selectChainWhere(resolveAtWhere: unknown[] = []) {
|
||||
const thenable = { then: (resolve: (v: unknown) => void) => resolve(resolveAtWhere) };
|
||||
return {
|
||||
from: vi.fn().mockReturnValue({
|
||||
where: vi.fn().mockReturnValue(thenable),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
/** Build an insert chain that resolves at .returning() or .values() */
|
||||
export function insertChain(resolveAtReturning: unknown[] = []) {
|
||||
const returningFn = vi.fn().mockResolvedValue(resolveAtReturning);
|
||||
@@ -46,6 +80,18 @@ export function updateChain(resolveAtWhere: unknown[] = []) {
|
||||
};
|
||||
}
|
||||
|
||||
/** Build an update chain with .where().returning() */
|
||||
export function updateChainReturning(resolveAtReturning: unknown[] = []) {
|
||||
const returningFn = vi.fn().mockResolvedValue(resolveAtReturning);
|
||||
return {
|
||||
set: vi.fn().mockReturnValue({
|
||||
where: vi.fn().mockReturnValue({
|
||||
returning: returningFn,
|
||||
}),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
/** Build a delete chain that resolves at .where() */
|
||||
export function deleteChain() {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user