|
| 1 | +// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +import { describe, it, expect } from 'vitest'; |
| 4 | +import { SysPresence } from './sys-presence.object'; |
| 5 | + |
| 6 | +describe('SysPresence object definition', () => { |
| 7 | + it('should have correct namespace and name', () => { |
| 8 | + expect(SysPresence.namespace).toBe('sys'); |
| 9 | + expect(SysPresence.name).toBe('presence'); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should auto-derive tableName as sys_presence', () => { |
| 13 | + expect(SysPresence.tableName).toBe('sys_presence'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should be a system object', () => { |
| 17 | + expect(SysPresence.isSystem).toBe(true); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should have label and pluralLabel', () => { |
| 21 | + expect(SysPresence.label).toBe('Presence'); |
| 22 | + expect(SysPresence.pluralLabel).toBe('Presences'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should define all presence protocol fields', () => { |
| 26 | + const fieldKeys = Object.keys(SysPresence.fields); |
| 27 | + expect(fieldKeys).toContain('id'); |
| 28 | + expect(fieldKeys).toContain('created_at'); |
| 29 | + expect(fieldKeys).toContain('updated_at'); |
| 30 | + expect(fieldKeys).toContain('user_id'); |
| 31 | + expect(fieldKeys).toContain('session_id'); |
| 32 | + expect(fieldKeys).toContain('status'); |
| 33 | + expect(fieldKeys).toContain('last_seen'); |
| 34 | + expect(fieldKeys).toContain('current_location'); |
| 35 | + expect(fieldKeys).toContain('device'); |
| 36 | + expect(fieldKeys).toContain('custom_status'); |
| 37 | + expect(fieldKeys).toContain('metadata'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should have status field with correct options', () => { |
| 41 | + const statusField = SysPresence.fields.status; |
| 42 | + expect(statusField.type).toBe('select'); |
| 43 | + expect(statusField.options).toEqual([ |
| 44 | + { value: 'online', label: 'Online' }, |
| 45 | + { value: 'away', label: 'Away' }, |
| 46 | + { value: 'busy', label: 'Busy' }, |
| 47 | + { value: 'offline', label: 'Offline' }, |
| 48 | + ]); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should have device field with correct options', () => { |
| 52 | + const deviceField = SysPresence.fields.device; |
| 53 | + expect(deviceField.type).toBe('select'); |
| 54 | + expect(deviceField.options).toEqual([ |
| 55 | + { value: 'desktop', label: 'Desktop' }, |
| 56 | + { value: 'mobile', label: 'Mobile' }, |
| 57 | + { value: 'tablet', label: 'Tablet' }, |
| 58 | + { value: 'other', label: 'Other' }, |
| 59 | + ]); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should have indexes on user_id, session_id, and status', () => { |
| 63 | + expect(SysPresence.indexes).toEqual([ |
| 64 | + { fields: ['user_id'], unique: false, type: 'btree' }, |
| 65 | + { fields: ['session_id'], unique: true, type: 'btree' }, |
| 66 | + { fields: ['status'], unique: false, type: 'btree' }, |
| 67 | + ]); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should have API enabled', () => { |
| 71 | + expect(SysPresence.enable?.apiEnabled).toBe(true); |
| 72 | + }); |
| 73 | +}); |
0 commit comments