|
| 1 | +import { describe, expect, test } from 'bun:test'; |
| 2 | +import { |
| 3 | + buildShorthandCollaborationInput, |
| 4 | + DEFAULT_SHORTHAND_COLLABORATION_PROVIDER_TYPE, |
| 5 | + parseCollaborationInput, |
| 6 | + resolveCollaborationProfile, |
| 7 | +} from '../collaboration'; |
| 8 | + |
| 9 | +describe('buildShorthandCollaborationInput', () => { |
| 10 | + test('uses y-websocket as the default provider type', () => { |
| 11 | + expect(DEFAULT_SHORTHAND_COLLABORATION_PROVIDER_TYPE).toBe('y-websocket'); |
| 12 | + }); |
| 13 | + |
| 14 | + test('returns a validated CollaborationInput with all params', () => { |
| 15 | + const input = buildShorthandCollaborationInput({ |
| 16 | + url: 'ws://localhost:4000', |
| 17 | + documentId: 'my-doc-room', |
| 18 | + onMissing: 'error', |
| 19 | + bootstrapSettlingMs: 2000, |
| 20 | + }); |
| 21 | + |
| 22 | + expect(input).toEqual({ |
| 23 | + providerType: 'y-websocket', |
| 24 | + url: 'ws://localhost:4000', |
| 25 | + documentId: 'my-doc-room', |
| 26 | + onMissing: 'error', |
| 27 | + bootstrapSettlingMs: 2000, |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + test('handles minimal params (url-only)', () => { |
| 32 | + const input = buildShorthandCollaborationInput({ url: 'ws://localhost:4000' }); |
| 33 | + |
| 34 | + expect(input.providerType).toBe('y-websocket'); |
| 35 | + expect(input.url).toBe('ws://localhost:4000'); |
| 36 | + expect(input.documentId).toBeUndefined(); |
| 37 | + expect(input.onMissing).toBeUndefined(); |
| 38 | + expect(input.bootstrapSettlingMs).toBeUndefined(); |
| 39 | + }); |
| 40 | + |
| 41 | + test('flows through to resolveCollaborationProfile with correct provider', () => { |
| 42 | + const input = buildShorthandCollaborationInput({ |
| 43 | + url: 'ws://localhost:4000', |
| 44 | + documentId: 'my-doc-room', |
| 45 | + }); |
| 46 | + const profile = resolveCollaborationProfile(input, 'fallback-session'); |
| 47 | + |
| 48 | + expect(profile.providerType).toBe('y-websocket'); |
| 49 | + expect(profile.documentId).toBe('my-doc-room'); |
| 50 | + }); |
| 51 | +}); |
| 52 | + |
| 53 | +describe('parseCollaborationInput', () => { |
| 54 | + test('accepts explicit hocuspocus provider type', () => { |
| 55 | + const input = parseCollaborationInput({ |
| 56 | + providerType: 'hocuspocus', |
| 57 | + url: 'ws://localhost:1234', |
| 58 | + documentId: 'room-1', |
| 59 | + }); |
| 60 | + |
| 61 | + expect(input.providerType).toBe('hocuspocus'); |
| 62 | + }); |
| 63 | +}); |
0 commit comments