Move unit tests into e2e folder

This commit is contained in:
beatz174-bit
2025-12-02 18:23:12 +10:00
parent 5bdf20a829
commit 00cefaa96d
7 changed files with 33 additions and 27 deletions
+53
View File
@@ -0,0 +1,53 @@
import { vi } from 'vitest';
export type TableMock<T = any> = {
toArray: ReturnType<typeof vi.fn>;
add: ReturnType<typeof vi.fn>;
update: ReturnType<typeof vi.fn>;
where: ReturnType<typeof vi.fn>;
filter: ReturnType<typeof vi.fn>;
count: ReturnType<typeof vi.fn>;
};
const createWhere = () => ({
equals: vi.fn().mockReturnValue({ first: vi.fn().mockResolvedValue(undefined) }),
});
export const makeTableMock = <T = any>(items: T[] = []): TableMock<T> => ({
toArray: vi.fn().mockResolvedValue([...items]),
add: vi.fn().mockResolvedValue(undefined),
update: vi.fn().mockResolvedValue(undefined),
where: vi.fn().mockImplementation(() => createWhere()),
filter: vi.fn().mockReturnValue({ first: vi.fn().mockResolvedValue(undefined) }),
count: vi.fn().mockResolvedValue(0),
});
export const makeMockDb = (overrides: Partial<Record<string, any>> = {}) => {
const products = makeTableMock(overrides.products ?? []);
const categories = makeTableMock(overrides.categories ?? []);
const pickLists = makeTableMock(overrides.pickLists ?? []);
const pickItems = makeTableMock(overrides.pickItems ?? []);
const importExportLogs = makeTableMock(overrides.importExportLogs ?? []);
const transaction = vi
.fn()
.mockImplementation(async (_mode: any, ...args: any[]) => {
const cb = args[args.length - 1];
if (typeof cb === 'function') {
return cb();
}
return undefined;
});
const open = vi.fn().mockResolvedValue(undefined);
return {
products,
categories,
pickLists,
pickItems,
importExportLogs,
transaction,
open,
};
};