Barazo lexicon schemas and TypeScript types barazo.forum
at main 147 lines 5.2 kB view raw
1import { describe, it, expect } from 'vitest' 2import { 3 ForumBarazoTopicPost, 4 ForumBarazoTopicReply, 5 ForumBarazoInteractionReaction, 6 ForumBarazoInteractionVote, 7 ForumBarazoActorPreferences, 8 ForumBarazoDefs, 9 LEXICON_IDS, 10 schemas, 11 ids, 12} from '../src/index.js' 13 14describe('generated type exports', () => { 15 it('exports ForumBarazoTopicPost with Record type and validators', () => { 16 expect(ForumBarazoTopicPost.isRecord).toBeTypeOf('function') 17 expect(ForumBarazoTopicPost.validateRecord).toBeTypeOf('function') 18 }) 19 20 it('exports ForumBarazoTopicReply with Record type and validators', () => { 21 expect(ForumBarazoTopicReply.isRecord).toBeTypeOf('function') 22 expect(ForumBarazoTopicReply.validateRecord).toBeTypeOf('function') 23 }) 24 25 it('exports ForumBarazoInteractionReaction with Record type and validators', () => { 26 expect(ForumBarazoInteractionReaction.isRecord).toBeTypeOf('function') 27 expect(ForumBarazoInteractionReaction.validateRecord).toBeTypeOf('function') 28 }) 29 30 it('exports ForumBarazoInteractionVote with Record type and validators', () => { 31 expect(ForumBarazoInteractionVote.isRecord).toBeTypeOf('function') 32 expect(ForumBarazoInteractionVote.validateRecord).toBeTypeOf('function') 33 }) 34 35 it('exports ForumBarazoActorPreferences with Record type and validators', () => { 36 expect(ForumBarazoActorPreferences.isRecord).toBeTypeOf('function') 37 expect(ForumBarazoActorPreferences.validateRecord).toBeTypeOf('function') 38 }) 39 40 it('exports ForumBarazoDefs with CommunityRef validators', () => { 41 expect(ForumBarazoDefs.isCommunityRef).toBeTypeOf('function') 42 expect(ForumBarazoDefs.validateCommunityRef).toBeTypeOf('function') 43 }) 44 45 it('exports reaction token constants', () => { 46 expect(ForumBarazoInteractionReaction.LIKE).toBe('forum.barazo.interaction.reaction#like') 47 expect(ForumBarazoInteractionReaction.HEART).toBe('forum.barazo.interaction.reaction#heart') 48 expect(ForumBarazoInteractionReaction.THUMBSUP).toBe( 49 'forum.barazo.interaction.reaction#thumbsup' 50 ) 51 }) 52}) 53 54describe('LEXICON_IDS constants', () => { 55 it('has correct TopicPost ID', () => { 56 expect(LEXICON_IDS.TopicPost).toBe('forum.barazo.topic.post') 57 }) 58 59 it('has correct TopicReply ID', () => { 60 expect(LEXICON_IDS.TopicReply).toBe('forum.barazo.topic.reply') 61 }) 62 63 it('has correct Reaction ID', () => { 64 expect(LEXICON_IDS.Reaction).toBe('forum.barazo.interaction.reaction') 65 }) 66 67 it('has correct Vote ID', () => { 68 expect(LEXICON_IDS.Vote).toBe('forum.barazo.interaction.vote') 69 }) 70 71 it('has correct ActorPreferences ID', () => { 72 expect(LEXICON_IDS.ActorPreferences).toBe('forum.barazo.actor.preferences') 73 }) 74 75 it('has correct AuthForumAccess ID', () => { 76 expect(LEXICON_IDS.AuthForumAccess).toBe('forum.barazo.authForumAccess') 77 }) 78}) 79 80describe('generated schemas', () => { 81 it('exports schemas array', () => { 82 expect(Array.isArray(schemas)).toBe(true) 83 expect(schemas.length).toBeGreaterThan(0) 84 }) 85 86 it('schemas contain all Barazo lexicon IDs', () => { 87 const schemaIds = schemas.map((s: Record<string, unknown>) => s['id'] as string) 88 expect(schemaIds).toContain('forum.barazo.topic.post') 89 expect(schemaIds).toContain('forum.barazo.topic.reply') 90 expect(schemaIds).toContain('forum.barazo.interaction.reaction') 91 expect(schemaIds).toContain('forum.barazo.interaction.vote') 92 expect(schemaIds).toContain('forum.barazo.actor.preferences') 93 expect(schemaIds).toContain('forum.barazo.authForumAccess') 94 }) 95}) 96 97describe('generated ids map', () => { 98 it('maps ForumBarazoTopicPost correctly', () => { 99 expect(ids.ForumBarazoTopicPost).toBe('forum.barazo.topic.post') 100 }) 101 102 it('maps ForumBarazoTopicReply correctly', () => { 103 expect(ids.ForumBarazoTopicReply).toBe('forum.barazo.topic.reply') 104 }) 105 106 it('maps ForumBarazoInteractionReaction correctly', () => { 107 expect(ids.ForumBarazoInteractionReaction).toBe('forum.barazo.interaction.reaction') 108 }) 109 110 it('maps ForumBarazoInteractionVote correctly', () => { 111 expect(ids.ForumBarazoInteractionVote).toBe('forum.barazo.interaction.vote') 112 }) 113 114 it('maps ForumBarazoActorPreferences correctly', () => { 115 expect(ids.ForumBarazoActorPreferences).toBe('forum.barazo.actor.preferences') 116 }) 117 118 it('maps ForumBarazoAuthForumAccess correctly', () => { 119 expect(ids.ForumBarazoAuthForumAccess).toBe('forum.barazo.authForumAccess') 120 }) 121}) 122 123describe('isRecord type guards', () => { 124 it('ForumBarazoTopicPost.isRecord identifies correct $type', () => { 125 expect( 126 ForumBarazoTopicPost.isRecord({ 127 $type: 'forum.barazo.topic.post', 128 title: 'Test', 129 }) 130 ).toBe(true) 131 }) 132 133 it('ForumBarazoTopicPost.isRecord rejects wrong $type', () => { 134 expect( 135 ForumBarazoTopicPost.isRecord({ 136 $type: 'forum.barazo.topic.reply', 137 content: 'Test', 138 }) 139 ).toBe(false) 140 }) 141 142 it('ForumBarazoTopicPost.isRecord rejects non-objects', () => { 143 expect(ForumBarazoTopicPost.isRecord('string')).toBe(false) 144 expect(ForumBarazoTopicPost.isRecord(null)).toBe(false) 145 expect(ForumBarazoTopicPost.isRecord(undefined)).toBe(false) 146 }) 147})