Files
speckle-server/packages/objectloader2/src/operations/databases/indexedDatabase.spec.ts
T
Adam Hathcock 2b828a5eeb (OL2) refactor read queue (#4948)
* Rename to saveBatch

* forgot a file

* first pass of cacheReader

* OL2 tests have infinite timeout

* OL2 refactor works

* fix for tests

* get rid of pumps and fix test

* lint fix

* redo mermaid diagrams

* add readme section on deferment
2025-06-17 08:24:05 +01:00

38 lines
1.0 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { IDBFactory, IDBKeyRange } from 'fake-indexeddb'
import IndexedDatabase, { IndexedDatabaseOptions } from './indexedDatabase.js'
import { Item, Base } from '../../types/types.js'
// Mock Item
const defaultItem = (id: string): Item => ({
baseId: id,
base: { foo: 'bar' } as unknown as Base
})
describe('IndexedDatabase', () => {
let db: IndexedDatabase
let options: IndexedDatabaseOptions
beforeEach(() => {
options = { indexedDB: new IDBFactory(), keyRange: IDBKeyRange }
db = new IndexedDatabase(options)
})
afterEach(async () => {
await db.disposeAsync()
})
it('should add and get multiple items', async () => {
const items = [defaultItem('id1'), defaultItem('id2')]
await db.saveBatch({ batch: items })
const result = await db.getAll(['id1', 'id2'])
expect(result).toMatchSnapshot()
expect(result).toEqual(items)
})
it('should dispose without error', async () => {
await expect(db.disposeAsync()).resolves.not.toThrow()
})
})