Skip to content

Commit 1c3df1f

Browse files
author
waleed
committed
update tests
1 parent d8f0ae8 commit 1c3df1f

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

apps/sim/app/api/knowledge/utils.test.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,23 @@ vi.mock('@sim/db', () => {
117117
return {
118118
db: {
119119
select: vi.fn(() => selectBuilder),
120-
update: () => ({
121-
set: () => ({
122-
where: () => Promise.resolve(),
120+
update: (table: any) => ({
121+
set: (payload: any) => ({
122+
where: () => {
123+
const tableSymbols = Object.getOwnPropertySymbols(table || {})
124+
const baseNameSymbol = tableSymbols.find((s) => s.toString().includes('BaseName'))
125+
const tableName = baseNameSymbol ? table[baseNameSymbol] : ''
126+
if (tableName === 'knowledge_base') {
127+
dbOps.order.push('updateKb')
128+
dbOps.updatePayloads.push(payload)
129+
} else if (tableName === 'document') {
130+
if (payload.processingStatus !== 'processing') {
131+
dbOps.order.push('updateDoc')
132+
dbOps.updatePayloads.push(payload)
133+
}
134+
}
135+
return Promise.resolve()
136+
},
123137
}),
124138
}),
125139
transaction: vi.fn(async (fn: any) => {
@@ -131,11 +145,11 @@ vi.mock('@sim/db', () => {
131145
return Promise.resolve()
132146
},
133147
}),
134-
update: () => ({
148+
update: (table: any) => ({
135149
set: (payload: any) => ({
136150
where: () => {
137151
dbOps.updatePayloads.push(payload)
138-
const label = dbOps.updatePayloads.length === 1 ? 'updateDoc' : 'updateKb'
152+
const label = payload.processingStatus !== undefined ? 'updateDoc' : 'updateKb'
139153
dbOps.order.push(label)
140154
return Promise.resolve()
141155
},
@@ -169,6 +183,9 @@ describe('Knowledge Utils', () => {
169183

170184
describe('processDocumentAsync', () => {
171185
it.concurrent('should insert embeddings before updating document counters', async () => {
186+
kbRows.push({ id: 'kb1', userId: 'user1', workspaceId: null })
187+
docRows.push({ id: 'doc1', knowledgeBaseId: 'kb1' })
188+
172189
await processDocumentAsync(
173190
'kb1',
174191
'doc1',

0 commit comments

Comments
 (0)