-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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: { | ||
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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... ? |
||
}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, fixed here