WIP: A simple cli for daily tangled use cases and AI integration. This is for my personal use right now, but happy if others get mileage from it! :)
1import { describe, expect, it, vi } from 'vitest';
2import type { TangledApiClient } from '../../src/lib/api-client.js';
3import { requireAuth } from '../../src/utils/auth-helpers.js';
4
5// Mock API client factory
6const createMockClient = (
7 authenticated: boolean,
8 session: { did: string; handle: string } | null
9): TangledApiClient => {
10 return {
11 isAuthenticated: vi.fn(async () => authenticated),
12 getSession: vi.fn(() => session),
13 } as unknown as TangledApiClient;
14};
15
16describe('requireAuth', () => {
17 it('should return session when authenticated', async () => {
18 const mockSession = { did: 'did:plc:test123', handle: 'test.bsky.social' };
19 const mockClient = createMockClient(true, mockSession);
20
21 const result = await requireAuth(mockClient);
22
23 expect(result).toEqual(mockSession);
24 });
25
26 it('should throw error when not authenticated', async () => {
27 const mockClient = createMockClient(false, null);
28
29 await expect(requireAuth(mockClient)).rejects.toThrow(
30 'Must be authenticated. Run "tangled auth login" first.'
31 );
32 });
33
34 it('should throw error when authenticated but no session', async () => {
35 const mockClient = createMockClient(true, null);
36
37 await expect(requireAuth(mockClient)).rejects.toThrow('No active session found');
38 });
39});