Skip to content

Commit eef6dd7

Browse files
authored
fix tests
1 parent d39eae0 commit eef6dd7

File tree

15 files changed

+143
-77
lines changed

15 files changed

+143
-77
lines changed

src/database/repositories/dataImporter/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export class DataImporterRepos {
138138
shouldInsertSessionAgents.map(({ id }, index) => ({
139139
agentId: agentMapArray[index].id,
140140
sessionId: sessionIdMap[id],
141+
userId: this.userId,
141142
})),
142143
);
143144
}
@@ -291,6 +292,7 @@ export class DataImporterRepos {
291292
state: msg.pluginState,
292293
toolCallId: msg.tool_call_id,
293294
type: msg.plugin?.type,
295+
userId: this.userId,
294296
})),
295297
);
296298
}
@@ -302,6 +304,7 @@ export class DataImporterRepos {
302304
translateInserts.map((msg) => ({
303305
id: messageIdMap[msg.id],
304306
...msg.extra?.translate,
307+
userId: this.userId,
305308
})),
306309
);
307310
}

src/database/server/models/__tests__/agent.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('AgentModel', () => {
7777
const sessionId = 'test-session-id';
7878
await serverDB.insert(agents).values({ id: agentId, userId });
7979
await serverDB.insert(sessions).values({ id: sessionId, userId });
80-
await serverDB.insert(agentsToSessions).values({ agentId, sessionId });
80+
await serverDB.insert(agentsToSessions).values({ agentId, sessionId, userId });
8181

8282
const result = await agentModel.findBySessionId(sessionId);
8383

src/database/server/models/__tests__/chunk.test.ts

+20-17
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ describe('ChunkModel', () => {
124124
.values([{ text: 'Non-Orphan Chunk', userId }])
125125
.returning();
126126

127-
await serverDB.insert(fileChunks).values([{ fileId: '1', chunkId: nonOrphanChunk.id }]);
127+
await serverDB
128+
.insert(fileChunks)
129+
.values([{ fileId: '1', chunkId: nonOrphanChunk.id, userId }]);
128130

129131
// Execute the method
130132
await chunkModel.deleteOrphanChunks();
@@ -146,8 +148,8 @@ describe('ChunkModel', () => {
146148
.returning();
147149

148150
await serverDB.insert(fileChunks).values([
149-
{ fileId: '1', chunkId: chunk1.id },
150-
{ fileId: '2', chunkId: chunk2.id },
151+
{ fileId: '1', chunkId: chunk1.id, userId },
152+
{ fileId: '2', chunkId: chunk2.id, userId },
151153
]);
152154

153155
// Execute the method
@@ -180,8 +182,8 @@ describe('ChunkModel', () => {
180182
.returning();
181183

182184
await serverDB.insert(fileChunks).values([
183-
{ fileId, chunkId: chunk1.id },
184-
{ fileId, chunkId: chunk2.id },
185+
{ fileId, chunkId: chunk1.id, userId },
186+
{ fileId, chunkId: chunk2.id, userId },
185187
]);
186188

187189
await serverDB.insert(embeddings).values([
@@ -273,9 +275,9 @@ describe('ChunkModel', () => {
273275
.returning();
274276

275277
await serverDB.insert(fileChunks).values([
276-
{ fileId, chunkId: chunk1.id },
277-
{ fileId, chunkId: chunk2.id },
278-
{ fileId, chunkId: chunk3.id },
278+
{ fileId, chunkId: chunk1.id, userId },
279+
{ fileId, chunkId: chunk2.id, userId },
280+
{ fileId, chunkId: chunk3.id, userId },
279281
]);
280282

281283
const result = await chunkModel.findByFileId(fileId, 0);
@@ -299,8 +301,8 @@ describe('ChunkModel', () => {
299301
.returning();
300302

301303
await serverDB.insert(fileChunks).values([
302-
{ fileId, chunkId: chunk1.id },
303-
{ fileId, chunkId: chunk2.id },
304+
{ fileId, chunkId: chunk1.id, userId },
305+
{ fileId, chunkId: chunk2.id, userId },
304306
]);
305307

306308
const result = await chunkModel.getChunksTextByFileId(fileId);
@@ -324,9 +326,9 @@ describe('ChunkModel', () => {
324326
.returning();
325327

326328
await serverDB.insert(fileChunks).values([
327-
{ fileId: '1', chunkId: chunk1.id },
328-
{ fileId: '1', chunkId: chunk2.id },
329-
{ fileId: '2', chunkId: chunk3.id },
329+
{ fileId: '1', chunkId: chunk1.id, userId },
330+
{ fileId: '1', chunkId: chunk2.id, userId },
331+
{ fileId: '2', chunkId: chunk3.id, userId },
330332
]);
331333

332334
const result = await chunkModel.countByFileIds(fileIds);
@@ -355,8 +357,8 @@ describe('ChunkModel', () => {
355357
.returning();
356358

357359
await serverDB.insert(fileChunks).values([
358-
{ fileId, chunkId: chunk1.id },
359-
{ fileId, chunkId: chunk2.id },
360+
{ fileId, chunkId: chunk1.id, userId },
361+
{ fileId, chunkId: chunk2.id, userId },
360362
]);
361363

362364
const result = await chunkModel.countByFileId(fileId);
@@ -383,8 +385,8 @@ describe('ChunkModel', () => {
383385
.returning();
384386

385387
await serverDB.insert(fileChunks).values([
386-
{ fileId, chunkId: chunk1.id },
387-
{ fileId, chunkId: chunk2.id },
388+
{ fileId, chunkId: chunk1.id, userId },
389+
{ fileId, chunkId: chunk2.id, userId },
388390
]);
389391

390392
await serverDB.insert(embeddings).values([
@@ -511,6 +513,7 @@ content in Table html is below:
511513
chunkResult.map((chunk) => ({
512514
fileId,
513515
chunkId: chunk.id,
516+
userId,
514517
})),
515518
);
516519

src/database/server/models/__tests__/file.test.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ describe('FileModel', () => {
9595
size: 100,
9696
url: 'https://example.com/global-file.txt',
9797
metadata: { key: 'value' },
98+
creator: userId,
9899
};
99100

100101
const result = await fileModel.createGlobalFile(globalFile);
@@ -115,6 +116,7 @@ describe('FileModel', () => {
115116
size: 100,
116117
url: 'https://example.com/existing-file.txt',
117118
metadata: { key: 'value' },
119+
creator: userId,
118120
};
119121

120122
await serverDB.insert(globalFiles).values(globalFile);
@@ -137,6 +139,7 @@ describe('FileModel', () => {
137139
url: 'https://example.com/file1.txt',
138140
size: 100,
139141
fileType: 'text/plain',
142+
creator: userId,
140143
});
141144

142145
const { id } = await fileModel.create({
@@ -163,6 +166,7 @@ describe('FileModel', () => {
163166
url: 'https://example.com/file1.txt',
164167
size: 100,
165168
fileType: 'text/plain',
169+
creator: userId,
166170
});
167171

168172
const { id } = await fileModel.create({
@@ -192,12 +196,14 @@ describe('FileModel', () => {
192196
url: 'https://example.com/file1.txt',
193197
size: 100,
194198
fileType: 'text/plain',
199+
creator: userId,
195200
});
196201
await fileModel.createGlobalFile({
197202
hashId: '2',
198203
url: 'https://example.com/file2.txt',
199204
size: 200,
200205
fileType: 'text/plain',
206+
creator: userId,
201207
});
202208

203209
const file1 = await fileModel.create({
@@ -240,12 +246,14 @@ describe('FileModel', () => {
240246
url: 'https://example.com/file1.txt',
241247
size: 100,
242248
fileType: 'text/plain',
249+
creator: userId,
243250
});
244251
await fileModel.createGlobalFile({
245252
hashId: '2',
246253
url: 'https://example.com/file2.txt',
247254
size: 200,
248255
fileType: 'text/plain',
256+
creator: userId,
249257
});
250258

251259
const file1 = await fileModel.create({
@@ -450,7 +458,7 @@ describe('FileModel', () => {
450458
]);
451459
await serverDB
452460
.insert(knowledgeBaseFiles)
453-
.values([{ fileId: 'file1', knowledgeBaseId: 'kb1' }]);
461+
.values([{ fileId: 'file1', knowledgeBaseId: 'kb1', userId }]);
454462
});
455463

456464
it('should query files in a specific knowledge base', async () => {
@@ -551,12 +559,14 @@ describe('FileModel', () => {
551559
url: 'https://example.com/document.pdf',
552560
size: 1000,
553561
fileType: 'application/pdf',
562+
creator: userId,
554563
},
555564
{
556565
hashId: 'hash2',
557566
url: 'https://example.com/image.jpg',
558567
size: 500,
559568
fileType: 'image/jpeg',
569+
creator: userId,
560570
},
561571
]);
562572

@@ -674,6 +684,7 @@ describe('FileModel', () => {
674684
size: 100,
675685
url: 'https://example.com/global-file.txt',
676686
metadata: { key: 'value' },
687+
creator: userId,
677688
};
678689

679690
await serverDB.insert(globalFiles).values(globalFile);
@@ -700,12 +711,14 @@ describe('FileModel', () => {
700711
fileType: 'text/plain',
701712
size: 100,
702713
url: 'https://example.com/file1.txt',
714+
creator: userId,
703715
};
704716
const globalFiles2 = {
705717
hashId: 'hash2',
706718
fileType: 'text/plain',
707719
size: 200,
708720
url: 'https://example.com/file2.txt',
721+
creator: userId,
709722
};
710723

711724
await serverDB.insert(globalFiles).values([globalFiles1, globalFiles2]);

src/database/server/models/__tests__/knowledgeBase.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,14 @@ describe('KnowledgeBaseModel', () => {
160160
url: 'https://example.com/document.pdf',
161161
size: 1000,
162162
fileType: 'application/pdf',
163+
creator: userId,
163164
},
164165
{
165166
hashId: 'hash2',
166167
url: 'https://example.com/image.jpg',
167168
size: 500,
168169
fileType: 'image/jpeg',
170+
creator: userId,
169171
},
170172
]);
171173

@@ -198,12 +200,14 @@ describe('KnowledgeBaseModel', () => {
198200
url: 'https://example.com/document.pdf',
199201
size: 1000,
200202
fileType: 'application/pdf',
203+
creator: userId,
201204
},
202205
{
203206
hashId: 'hash2',
204207
url: 'https://example.com/image.jpg',
205208
size: 500,
206209
fileType: 'image/jpeg',
210+
creator: userId,
207211
},
208212
]);
209213

0 commit comments

Comments
 (0)