Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

stores.test.ts

44 lines1.4 KB

1import { describe, expect, it } from 'vitest'
2import { inMemoryTaskStore } from '../../src/server/stores'
3​
4const taskRecord = {
5 status: 'working',
6 progress: 1,
7}
8​
9describe('inMemoryTaskStore', () => {
10 it('returns the value that set saved', async () => {
11 const store = inMemoryTaskStore()
12 await store.set('item-1', taskRecord)
13 expect(await store.get('item-1')).toEqual(taskRecord)
14 })
15​
16 it('returns null when the id is missing', async () => {
17 const store = inMemoryTaskStore()
18 expect(await store.get('missing')).toBeNull()
19 })
20​
21 it('returns null for a deleted id and keeps the other id', async () => {
22 const store = inMemoryTaskStore()
23 await store.set('item-1', taskRecord)
24 await store.set('item-2', taskRecord)
25 await store.delete('item-1')
26 expect(await store.get('item-1')).toBeNull()
27 expect(await store.get('item-2')).toEqual(taskRecord)
28 })
29​
30 it('replaces the value when set uses the same id', async () => {
31 const store = inMemoryTaskStore()
32 await store.set('item-1', taskRecord)
33 await store.set('item-1', { replaced: true })
34 expect(await store.get('item-1')).toEqual({ replaced: true })
35 })
36​
37 it('does not share entries with a second call', async () => {
38 const first = inMemoryTaskStore()
39 const second = inMemoryTaskStore()
40 await first.set('item-1', taskRecord)
41 expect(await second.get('item-1')).toBeNull()
42 expect(await first.get('item-1')).toEqual(taskRecord)
43 })
44})