Skip to content

Commit

Permalink
[Security assistant] Update conversations api improvement (elastic#20…
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic authored and viduni94 committed Jan 23, 2025
1 parent 7e1acd3 commit 1e05689
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import {
} from '../../__mocks__/conversations_schema.mock';
import { authenticatedUser } from '../../__mocks__/user';
import { updateConversationRoute } from './update_route';
import expect from 'expect';

describe('Update conversation route', () => {
let server: ReturnType<typeof serverMock.create>;
let { clients, context } = requestContextMock.createTools();
const mockUser1 = authenticatedUser;

beforeEach(() => {
jest.clearAllMocks();
server = serverMock.create();
({ clients, context } = requestContextMock.createTools());

Expand Down Expand Up @@ -145,5 +147,27 @@ describe('Update conversation route', () => {
`messages.0.role: Invalid enum value. Expected 'system' | 'user' | 'assistant', received 'invalid'`
);
});

// validate id is correct, check happens on L71 in update_route.ts
test('validates id is correct', async () => {
const request = requestMock.create({
method: 'put',
path: ELASTIC_AI_ASSISTANT_CONVERSATIONS_URL_BY_ID,
body: {
...getUpdateConversationSchemaMock(),
id: 'invalid-id',
},
params: { id: 'real-id' },
});
await server.inject(request, requestContextMock.convertContext(context));

expect(
clients.elasticAssistant.getAIAssistantConversationsDataClient.updateConversation
).toHaveBeenCalledWith(
expect.objectContaining({
conversationUpdateProps: expect.objectContaining({ id: 'real-id' }),
})
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const updateConversationRoute = (router: ElasticAssistantPluginRouter) =>
});
}
const conversation = await dataClient?.updateConversation({
conversationUpdateProps: request.body,
conversationUpdateProps: { ...request.body, id },
});
if (conversation == null) {
return assistantResponse.error({
Expand Down

0 comments on commit 1e05689

Please sign in to comment.