Fix lint issues in unit test helpers
This commit is contained in:
1 parent
f807857bec
commit
1030476ed1
4 files changed
+95
-51
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, test, vi, beforeEach } from 'vitest';
|
||||
import type { StockFillDB } from '../../src/db';
|
||||
import { makeMockDb } from '../utils/mockDb';
|
||||
|
||||
vi.mock('uuid', () => ({ v4: vi.fn(() => 'mock-uuid') }));
|
||||
@@ -11,15 +12,13 @@ describe('applyMigrations', () => {
|
||||
|
||||
test('creates category for product name and updates product to use new id', async () => {
|
||||
const db = makeMockDb();
|
||||
(db.categories.toArray as any)
|
||||
db.categories.toArray
|
||||
.mockResolvedValueOnce([])
|
||||
.mockResolvedValueOnce([{ id: 'mock-uuid', name: 'Beverages', created_at: 1, updated_at: 1 }]);
|
||||
(db.products.toArray as any).mockResolvedValueOnce([
|
||||
{ id: 'p1', category: 'Beverages', name: 'Cola' },
|
||||
]);
|
||||
db.products.toArray.mockResolvedValueOnce([{ id: 'p1', category: 'Beverages', name: 'Cola' }]);
|
||||
|
||||
const { applyMigrations } = await import('../../src/db/migrations');
|
||||
await applyMigrations(db as any);
|
||||
await applyMigrations(db as unknown as StockFillDB);
|
||||
|
||||
expect(db.categories.add).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ id: 'mock-uuid', name: 'Beverages' }),
|
||||
@@ -29,15 +28,13 @@ describe('applyMigrations', () => {
|
||||
|
||||
test('skips update when product category already matches existing id', async () => {
|
||||
const db = makeMockDb();
|
||||
(db.categories.toArray as any)
|
||||
db.categories.toArray
|
||||
.mockResolvedValueOnce([{ id: 'cat-1', name: 'Snacks' }])
|
||||
.mockResolvedValueOnce([{ id: 'cat-1', name: 'Snacks' }]);
|
||||
(db.products.toArray as any).mockResolvedValueOnce([
|
||||
{ id: 'p2', category: 'cat-1', name: 'Chips' },
|
||||
]);
|
||||
db.products.toArray.mockResolvedValueOnce([{ id: 'p2', category: 'cat-1', name: 'Chips' }]);
|
||||
|
||||
const { applyMigrations } = await import('../../src/db/migrations');
|
||||
await applyMigrations(db as any);
|
||||
await applyMigrations(db as unknown as StockFillDB);
|
||||
|
||||
expect(db.categories.add).not.toHaveBeenCalled();
|
||||
expect(db.products.update).not.toHaveBeenCalled();
|
||||
@@ -45,16 +42,14 @@ describe('applyMigrations', () => {
|
||||
|
||||
test('normalizes pickList categories names to ids', async () => {
|
||||
const db = makeMockDb();
|
||||
(db.categories.toArray as any)
|
||||
db.categories.toArray
|
||||
.mockResolvedValueOnce([{ id: 'cat-fruit', name: 'Fruit' }])
|
||||
.mockResolvedValueOnce([{ id: 'cat-fruit', name: 'Fruit' }]);
|
||||
(db.products.toArray as any).mockResolvedValueOnce([]);
|
||||
(db.pickLists.toArray as any).mockResolvedValueOnce([
|
||||
{ id: 'pl-1', categories: ['Fruit'] },
|
||||
]);
|
||||
db.products.toArray.mockResolvedValueOnce([]);
|
||||
db.pickLists.toArray.mockResolvedValueOnce([{ id: 'pl-1', categories: ['Fruit'] }]);
|
||||
|
||||
const { applyMigrations } = await import('../../src/db/migrations');
|
||||
await applyMigrations(db as any);
|
||||
await applyMigrations(db as unknown as StockFillDB);
|
||||
|
||||
expect(db.pickLists.update).toHaveBeenCalledWith('pl-1', { categories: ['cat-fruit'] });
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user