mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
feat: add session pinning for pinned/recent session groups (#301)
* feat: add session pinning for pinned/recent session groups * refactor: extract buildSessionKey, deduplicate SessionCard rendering, clean up pins on delete
This commit is contained in:
1 parent
217f5bd989
commit
a9b6f7ce46
21 files changed
+762
-58
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { listSessionPins, toggleSessionPin } from './sessionPins'
|
||||
|
||||
describe('sessionPins', () => {
|
||||
const fetchMock = vi.fn()
|
||||
|
||||
beforeEach(() => {
|
||||
fetchMock.mockReset()
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
describe('listSessionPins', () => {
|
||||
it('calls GET /api/session-pins and returns pins array', async () => {
|
||||
const expectedPins = [
|
||||
{ sessionId: 's1', directory: '/a', pinnedAt: 100 },
|
||||
{ sessionId: 's2', directory: '/b', pinnedAt: 200 },
|
||||
]
|
||||
fetchMock.mockResolvedValue(
|
||||
new Response(JSON.stringify({ pins: expectedPins }), { status: 200 }),
|
||||
)
|
||||
|
||||
const result = await listSessionPins()
|
||||
|
||||
expect(result).toEqual(expectedPins)
|
||||
|
||||
const callUrl = fetchMock.mock.calls[0][0]
|
||||
expect(callUrl).toEqual(expect.stringContaining('/api/session-pins'))
|
||||
|
||||
const callOptions = fetchMock.mock.calls[0][1]
|
||||
expect(callOptions.method).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('toggleSessionPin', () => {
|
||||
it('calls PUT /api/session-pins with JSON body and returns pins', async () => {
|
||||
const input = { sessionId: 's1', directory: '/a', pinned: true }
|
||||
const expectedPins = [
|
||||
{ sessionId: 's1', directory: '/a', pinnedAt: 100 },
|
||||
]
|
||||
fetchMock.mockResolvedValue(
|
||||
new Response(JSON.stringify({ pins: expectedPins }), { status: 200 }),
|
||||
)
|
||||
|
||||
const result = await toggleSessionPin(input)
|
||||
|
||||
expect(result).toEqual(expectedPins)
|
||||
|
||||
const callUrl = fetchMock.mock.calls[0][0]
|
||||
expect(callUrl).toEqual(expect.stringContaining('/api/session-pins'))
|
||||
|
||||
const callOptions = fetchMock.mock.calls[0][1]
|
||||
expect(callOptions.method).toBe('PUT')
|
||||
expect(callOptions.headers['Content-Type']).toBe('application/json')
|
||||
|
||||
const body = JSON.parse(callOptions.body)
|
||||
expect(body).toEqual(input)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,17 @@
|
||||
import { fetchWrapper } from './fetchWrapper'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import type { SessionPin, ToggleSessionPinRequest } from '@opencode-manager/shared/schemas'
|
||||
|
||||
export async function listSessionPins(): Promise<SessionPin[]> {
|
||||
const res = await fetchWrapper<{ pins: SessionPin[] }>(`${API_BASE_URL}/api/session-pins`)
|
||||
return res.pins
|
||||
}
|
||||
|
||||
export async function toggleSessionPin(input: ToggleSessionPinRequest): Promise<SessionPin[]> {
|
||||
const res = await fetchWrapper<{ pins: SessionPin[] }>(`${API_BASE_URL}/api/session-pins`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(input),
|
||||
})
|
||||
return res.pins
|
||||
}
|
||||
Reference in new issue
Block a user