Skip to content

Commit

Permalink
🧪 test: adjust tests to new keyword search
Browse files Browse the repository at this point in the history
  • Loading branch information
cy948 committed Nov 19, 2024
1 parent 2536960 commit 6a0d71d
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/database/server/models/__tests__/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,18 @@ describe('SessionModel', () => {

it('should return sessions with matching title', async () => {
await serverDB.insert(sessions).values([
{ id: '1', userId, title: 'Hello World', description: 'Some description' },
{ id: '2', userId, title: 'Another Session', description: 'Another description' },
{ id: '1', userId },
{ id: '2', userId },
]);

await serverDB.insert(agents).values([
{ id: 'agent-1', userId, model: 'gpt-3.5-turbo', title: 'Hello, Agent 1' },
{ id: 'agent-2', userId, model: 'gpt-4', title: 'Agent 2' },
]);

await serverDB.insert(agentsToSessions).values([
{ agentId: 'agent-1', sessionId: '1' },
{ agentId: 'agent-2', sessionId: '2' },
]);

const result = await sessionModel.queryByKeyword('hello');
Expand All @@ -241,9 +251,21 @@ describe('SessionModel', () => {
});

it('should return sessions with matching description', async () => {
// The sessions has no title and desc,
// see: https://github.com/lobehub/lobe-chat/pull/4725
await serverDB.insert(sessions).values([
{ id: '1', userId, title: 'Session 1', description: 'Description with keyword' },
{ id: '2', userId, title: 'Session 2', description: 'Another description' },
{ id: '1', userId },
{ id: '2', userId },
]);

await serverDB.insert(agents).values([
{ id: 'agent-1', userId, model: 'gpt-3.5-turbo', title: 'Agent 1', description: 'Description with Keyword' },
{ id: 'agent-2', userId, model: 'gpt-4', title: 'Agent 2' },
]);

await serverDB.insert(agentsToSessions).values([
{ agentId: 'agent-1', sessionId: '1' },
{ agentId: 'agent-2', sessionId: '2' },
]);

const result = await sessionModel.queryByKeyword('keyword');
Expand All @@ -253,11 +275,23 @@ describe('SessionModel', () => {

it('should return sessions with matching title or description', async () => {
await serverDB.insert(sessions).values([
{ id: '1', userId },
{ id: '2', userId },
{ id: '3', userId },
]);

await serverDB.insert(agents).values([
{ id: '1', userId, title: 'Title with keyword', description: 'Some description' },
{ id: '2', userId, title: 'Another Session', description: 'Description with keyword' },
{ id: '3', userId, title: 'Third Session', description: 'Third description' },
]);

await serverDB.insert(agentsToSessions).values([
{ agentId: '1', sessionId: '1' },
{ agentId: '2', sessionId: '2' },
{ agentId: '3', sessionId: '3' },
]);

const result = await sessionModel.queryByKeyword('keyword');
expect(result).toHaveLength(2);
expect(result.map((s) => s.id)).toEqual(['1', '2']);
Expand Down

0 comments on commit 6a0d71d

Please sign in to comment.