Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution][Notes] - fix incorrect get_notes api for documentIds and savedObjectIds query parameters and adding api integration tests #196225

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const getNotesRoute = (router: SecuritySolutionPluginRouter) => {
return response.ok({ body });
}

// searching for all the notes associated with a specific for saved object id
// searching for all the notes associated with a specific saved object id
const options: SavedObjectsFindOptions = {
type: noteSavedObjectType,
hasReference: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type SuperTest from 'supertest';
import { v4 as uuidv4 } from 'uuid';
import { TimelineTypeEnum } from '@kbn/security-solution-plugin/common/api/timeline';
import { BareNote, TimelineTypeEnum } from '@kbn/security-solution-plugin/common/api/timeline';
import { NOTE_URL } from '@kbn/security-solution-plugin/common/constants';
import type { Client } from '@elastic/elasticsearch';
import { SECURITY_SOLUTION_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server';
Expand Down Expand Up @@ -53,82 +53,26 @@ export const deleteAllNotes = async (es: Client): Promise<void> => {
});
};

export const createNoteAssociatedWithDocumentOnly = async (
export const createNote = async (
supertest: SuperTest.Agent,
documentId: string,
noteText: string
note: {
documentId?: string;
savedObjectId?: string;
user?: string;
text: string;
}
) =>
await supertest
.patch(NOTE_URL)
.set('kbn-xsrf', 'true')
.send({
note: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💅 You could use the actual request body types here and in the cases below, so that it will be easier to refactor these tests once we are changing the request body types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, fixed here

eventId: documentId,
timelineId: '',
eventId: note.documentId || '',
timelineId: note.savedObjectId || '',
created: Date.now(),
createdBy: 'elastic',
createdBy: note.user || 'elastic',
updated: Date.now(),
updatedBy: 'elastic',
note: noteText,
},
});

export const createNoteAssociatedWithSavedObjectOnly = async (
supertest: SuperTest.Agent,
savedObjectId: string,
noteText: string
) =>
await supertest
.patch(NOTE_URL)
.set('kbn-xsrf', 'true')
.send({
note: {
eventId: '',
timelineId: savedObjectId,
created: Date.now(),
createdBy: 'elastic',
updated: Date.now(),
updatedBy: 'elastic',
note: noteText,
},
});

export const createNoteAssociatedWithDocumentAndSavedObject = async (
supertest: SuperTest.Agent,
documentId: string,
savedObjectId: string,
noteText: string
) =>
await supertest
.patch(NOTE_URL)
.set('kbn-xsrf', 'true')
.send({
note: {
eventId: documentId,
timelineId: savedObjectId,
created: Date.now(),
createdBy: 'elastic',
updated: Date.now(),
updatedBy: 'elastic',
note: noteText,
},
});

export const createNoteAssociatedWithNothing = async (
supertest: SuperTest.Agent,
noteText: string
) =>
await supertest
.patch(NOTE_URL)
.set('kbn-xsrf', 'true')
.send({
note: {
eventId: '',
timelineId: '',
created: Date.now(),
createdBy: 'elastic',
updated: Date.now(),
updatedBy: 'elastic',
note: noteText,
},
updatedBy: note.user || 'elastic',
note: note.text,
} as BareNote,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be PersistNoteRouteRequestBody

Copy link
Contributor Author

@PhilippeOberti PhilippeOberti Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense, if that's ok I made the change in this other PR (here) that way it saves some CI time as this PR is nearly done... ?

});
Loading