Barazo AppView backend barazo.forum
at main 54 lines 1.9 kB view raw
1import { describe, it, expect } from 'vitest' 2import { notifications } from '../../../../src/db/schema/notifications.js' 3import { getTableName, getTableColumns } from 'drizzle-orm' 4 5describe('notifications schema', () => { 6 it('should have the correct table name', () => { 7 expect(getTableName(notifications)).toBe('notifications') 8 }) 9 10 it('should have all required columns', () => { 11 const columns = getTableColumns(notifications) 12 const columnNames = Object.keys(columns) 13 14 expect(columnNames).toContain('id') 15 expect(columnNames).toContain('recipientDid') 16 expect(columnNames).toContain('type') 17 expect(columnNames).toContain('subjectUri') 18 expect(columnNames).toContain('actorDid') 19 expect(columnNames).toContain('communityDid') 20 expect(columnNames).toContain('read') 21 expect(columnNames).toContain('createdAt') 22 }) 23 24 it('should have id as primary key', () => { 25 const columns = getTableColumns(notifications) 26 expect(columns.id.primary).toBe(true) 27 }) 28 29 it('should mark required columns as not null', () => { 30 const columns = getTableColumns(notifications) 31 expect(columns.recipientDid.notNull).toBe(true) 32 expect(columns.type.notNull).toBe(true) 33 expect(columns.subjectUri.notNull).toBe(true) 34 expect(columns.actorDid.notNull).toBe(true) 35 expect(columns.communityDid.notNull).toBe(true) 36 expect(columns.read.notNull).toBe(true) 37 expect(columns.createdAt.notNull).toBe(true) 38 }) 39 40 it('should have exactly 8 columns', () => { 41 const columns = getTableColumns(notifications) 42 expect(Object.keys(columns)).toHaveLength(8) 43 }) 44 45 it('should have a default value for read (false)', () => { 46 const columns = getTableColumns(notifications) 47 expect(columns.read.hasDefault).toBe(true) 48 }) 49 50 it('should have a default value for createdAt', () => { 51 const columns = getTableColumns(notifications) 52 expect(columns.createdAt.hasDefault).toBe(true) 53 }) 54})