@@ -16,6 +16,10 @@ mockKnowledgeSchemas()
1616mockDrizzleOrm ( )
1717mockConsoleLogger ( )
1818
19+ vi . mock ( '@/lib/workspaces/permissions/utils' , ( ) => ( {
20+ getUserEntityPermissions : vi . fn ( ) . mockResolvedValue ( { role : 'owner' } ) ,
21+ } ) )
22+
1923describe ( 'Knowledge Base API Route' , ( ) => {
2024 const mockAuth$ = mockAuth ( )
2125
@@ -86,6 +90,7 @@ describe('Knowledge Base API Route', () => {
8690 const validKnowledgeBaseData = {
8791 name : 'Test Knowledge Base' ,
8892 description : 'Test description' ,
93+ workspaceId : 'test-workspace-id' ,
8994 chunkingConfig : {
9095 maxSize : 1024 ,
9196 minSize : 100 ,
@@ -133,11 +138,25 @@ describe('Knowledge Base API Route', () => {
133138 expect ( data . details ) . toBeDefined ( )
134139 } )
135140
141+ it ( 'should require workspaceId' , async ( ) => {
142+ mockAuth$ . mockAuthenticatedUser ( )
143+
144+ const req = createMockRequest ( 'POST' , { name : 'Test KB' } )
145+ const { POST } = await import ( '@/app/api/knowledge/route' )
146+ const response = await POST ( req )
147+ const data = await response . json ( )
148+
149+ expect ( response . status ) . toBe ( 400 )
150+ expect ( data . error ) . toBe ( 'Invalid request data' )
151+ expect ( data . details ) . toBeDefined ( )
152+ } )
153+
136154 it ( 'should validate chunking config constraints' , async ( ) => {
137155 mockAuth$ . mockAuthenticatedUser ( )
138156
139157 const invalidData = {
140158 name : 'Test KB' ,
159+ workspaceId : 'test-workspace-id' ,
141160 chunkingConfig : {
142161 maxSize : 100 , // 100 tokens = 400 characters
143162 minSize : 500 , // Invalid: minSize (500 chars) > maxSize (400 chars)
@@ -157,7 +176,7 @@ describe('Knowledge Base API Route', () => {
157176 it ( 'should use default values for optional fields' , async ( ) => {
158177 mockAuth$ . mockAuthenticatedUser ( )
159178
160- const minimalData = { name : 'Test KB' }
179+ const minimalData = { name : 'Test KB' , workspaceId : 'test-workspace-id' }
161180 const req = createMockRequest ( 'POST' , minimalData )
162181 const { POST } = await import ( '@/app/api/knowledge/route' )
163182 const response = await POST ( req )
0 commit comments